| 57 | self.assertLess(time.perf_counter() - start_time, 0.002) |
| 58 | |
| 59 | def test_constant_throughput(self): |
| 60 | class MyUser(User): |
| 61 | wait_time = constant_throughput(10) |
| 62 | |
| 63 | class TS(TaskSet): |
| 64 | pass |
| 65 | |
| 66 | ts = TS(MyUser(self.environment)) |
| 67 | |
| 68 | ts2 = TS(MyUser(self.environment)) |
| 69 | |
| 70 | previous_time = time.perf_counter() |
| 71 | for i in range(7): |
| 72 | ts.wait() |
| 73 | since_last_run = time.perf_counter() - previous_time |
| 74 | self.assertLess(abs(0.1 - since_last_run), 0.02) |
| 75 | previous_time = time.perf_counter() |
| 76 | time.sleep(random.random() * 0.1) |
| 77 | _ = ts2.wait_time() |
| 78 | _ = ts2.wait_time() |