Chris Mague 4 лет назад
Сommit
28fe597022
3 измененных файлов с 67 добавлено и 0 удалено
  1. 18 0
      README.md
  2. 26 0
      docker-compose.yml
  3. 23 0
      locustfile.py

+ 18 - 0
README.md

@@ -0,0 +1,18 @@
+# Test Locust in Docker
+
+## Running
+
+### Startup Containers
+
+```
+docker-compose up --scale worker=2
+```
+
+### Navigate to web interface
+
+
+(http://localhost:8099/)[Web UI]
+
+add in Host => http://websim:8080
+
+Star testing

+ 26 - 0
docker-compose.yml

@@ -0,0 +1,26 @@
+version: '3'
+
+services:
+  master:
+    image: locustio/locust
+    ports:
+     - "8099:8099"
+    volumes:
+      - ./:/mnt/locust
+    command: -f /mnt/locust/locustfile.py --master -H http://master:8089 --web-port=8099
+    links:
+      - "websim"
+  
+  worker:
+    image: locustio/locust
+    volumes:
+      - ./:/mnt/locust
+    command: -f /mnt/locust/locustfile.py --worker --master-host master
+    links:
+      - "websim"
+      - "master"
+  
+  websim:
+    image: maguec/websim
+    ports:
+     - "8091:8080"

+ 23 - 0
locustfile.py

@@ -0,0 +1,23 @@
+import random
+from locust import HttpUser, task, between
+
+class QuickstartUser(HttpUser):
+    wait_time = between(5, 9)
+
+    @task(10)
+    def health_page(self):
+        self.client.get("/health")
+
+    @task(100)
+    def timer_page(self):
+        rand_start = random.randint(1, 1000)
+        rand_end = random.randint(1000, 20000)
+        self.client.get(f"/timer/{rand_start}/{rand_end}", name="/timer")
+
+
+    @task(100)
+    def status_page(self):
+        codes = [ "301", "302", "404", "500", "503" ]
+        seed = random.randint(0, len(codes)-1)
+        self.client.get(f"/status/{codes[seed]}", name="/status")
+