Skip to content

subhlabh610/NFTTestingWithK6

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 K6 TypeScript Performance Testing Framework

📌 Overview

This project is a scalable, enterprise-grade performance testing framework built using:

  • k6 for load testing
  • TypeScript for maintainability and type safety
  • Docker for containerization
  • Kubernetes for distributed execution
  • Jenkins for CI/CD orchestration

The framework is designed with clean architecture principles to ensure:

  • Scalability
  • Reusability
  • Maintainability
  • Minimal impact on test scripts during upgrades

🏗️ Architecture

tests
   │
   ▼
services (business flows)
   │
   ▼
api client
   │
   ▼
auth manager (token handling)
   │
   ▼
http client
   │
   ▼
k6 engine

📂 Project Structure

k6-performance-framework
│
├── src
│   ├── config
│   │   └── env.ts
│   │
│   ├── auth
│   │   └── tokenManager.ts
│   │
│   ├── clients
│   │   └── apiClient.ts
│   │
│   ├── services
│   │   └── orderService.ts
│   │
│   ├── scenarios
│   │   ├── loadScenario.ts
│   │   ├── stressScenario.ts
│   │   └── scenarioManager.ts
│   │
│   ├── tests
│   │   └── orderLoadTest.ts
│
├── data
│   └── users.json
│
├── docker
│   └── Dockerfile
│
├── k8s
│   └── k6-job.yaml
│
├── jenkins
│   └── Jenkinsfile
│
├── dist
└── package.json

⚙️ Features

  • ✅ TypeScript-based framework
  • ✅ Environment-based execution (dev / qa / preprod)
  • ✅ Token-based authentication with auto-refresh
  • ✅ Scenario-driven execution (load, stress, spike)
  • ✅ Service-layer abstraction (business workflows)
  • ✅ Dockerized execution
  • ✅ Kubernetes distributed load generation
  • ✅ CI/CD ready (Jenkins pipeline)

🧪 Test Design Principles

  • Test scripts contain only business logic
  • No authentication or HTTP handling in tests
  • Fully decoupled architecture

Example Test

import { getScenario } from "../scenarios/scenarioManager"
import { createOrder } from "../services/orderService"

export const options = getScenario()

export default function () {
  createOrder()
}

🌍 Environment Configuration

Run tests for different environments using:

k6 run -e ENV=qa dist/tests/orderLoadTest.js

Supported environments:

dev
qa
preprod

📊 Scenario-Based Execution

Control test type dynamically:

k6 run -e SCENARIO=load
k6 run -e SCENARIO=stress

Supported scenarios:

  • load
  • stress
  • spike

🐳 Docker Execution

Build Image

docker build -t k6-framework -f docker/Dockerfile .

Run Test

docker run k6-framework run /app/tests/orderLoadTest.js

☸️ Kubernetes Execution

Deploy Load Test

kubectl apply -f k8s/k6-job.yaml

Check Pods

kubectl get pods

View Logs

kubectl logs <pod-name>

🔁 Distributed Load Testing

  • Multiple pods act as independent load generators
  • Each pod runs a k6 instance
  • Total load = sum of all pods

🔄 CI/CD Integration (Jenkins)

Pipeline supports parameters:

ENV
SCENARIO
TEST_SCRIPT

Example:

ENV = qa
SCENARIO = load
TEST_SCRIPT = orderLoadTest.js

⏱️ Scheduling

Tests can be scheduled using Jenkins cron:

0 2 * * *

Example: Run test every day at 2 AM


📌 Key Design Decisions

1. Separation of Concerns

  • Test → business flow
  • Service → API logic
  • Client → HTTP handling
  • Auth → token management

2. Token Management Strategy

  • Tokens are generated and refreshed automatically
  • No dependency on test scripts
  • Supports long-running distributed tests

3. Future-Proofing

Framework supports:

  • Easy migration to cloud Kubernetes
  • Switching authentication methods
  • Adding observability tools
  • Scaling to high load

🚀 Local vs Real Load Testing

Setup Capability
Local (Minikube) Framework validation
Distributed cl

About

Performance Testing with K6

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors