From 53de0910a1dcda9a4952f4bd1dcc2df67c2ad249 Mon Sep 17 00:00:00 2001 From: Nawaid Shamim Date: Thu, 15 May 2014 13:31:44 +0100 Subject: [PATCH 1/3] Fixing typos in events example --- examples/events.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/events.py b/examples/events.py index 9ecae509ad..7420c258d3 100644 --- a/examples/events.py +++ b/examples/events.py @@ -49,11 +49,11 @@ def on_report_to_master(client_id, data): def on_slave_report(client_id, data): """ - This event is triggered on the master isntance when a new stats report arrives + This event is triggered on the master instance when a new stats report arrives from a slave. Here we just add the content-length to the master's aggregated stats dict. """ - stats["content-length"] += stats["content-length"] + stats["content-length"] += data["content-length"] # Hook up the event listeners events.request_success += on_request_success From 2c6e6c032b6019dd14b0dd5d2858c2de929ff50e Mon Sep 17 00:00:00 2001 From: Nawaid Shamim Date: Fri, 16 May 2014 11:07:18 +0100 Subject: [PATCH 2/3] Fixing scope of variables in event handler function --- examples/events.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/events.py b/examples/events.py index 7420c258d3..ba0c52a7fe 100644 --- a/examples/events.py +++ b/examples/events.py @@ -36,6 +36,7 @@ def on_request_success(request_type, name, response_time, response_length): """ Event handler that get triggered on every successful request """ + global stats stats["content-length"] += response_length def on_report_to_master(client_id, data): @@ -44,6 +45,7 @@ def on_report_to_master(client_id, data): to be sent to the locust master. It will allow us to add our extra content-length data to the dict that is being sent, and then we clear the local stats in the slave. """ + global stats data["content-length"] = stats["content-length"] stats["content-length"] = 0 @@ -53,6 +55,7 @@ def on_slave_report(client_id, data): from a slave. Here we just add the content-length to the master's aggregated stats dict. """ + global stats stats["content-length"] += data["content-length"] # Hook up the event listeners From 2c1bee6143edc4170e19db14501e1c58c6259b0f Mon Sep 17 00:00:00 2001 From: Nawaid Shamim Date: Fri, 16 May 2014 11:57:48 +0100 Subject: [PATCH 3/3] removed global keywords --- examples/events.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/events.py b/examples/events.py index ba0c52a7fe..7420c258d3 100644 --- a/examples/events.py +++ b/examples/events.py @@ -36,7 +36,6 @@ def on_request_success(request_type, name, response_time, response_length): """ Event handler that get triggered on every successful request """ - global stats stats["content-length"] += response_length def on_report_to_master(client_id, data): @@ -45,7 +44,6 @@ def on_report_to_master(client_id, data): to be sent to the locust master. It will allow us to add our extra content-length data to the dict that is being sent, and then we clear the local stats in the slave. """ - global stats data["content-length"] = stats["content-length"] stats["content-length"] = 0 @@ -55,7 +53,6 @@ def on_slave_report(client_id, data): from a slave. Here we just add the content-length to the master's aggregated stats dict. """ - global stats stats["content-length"] += data["content-length"] # Hook up the event listeners