Locust: test_cpu_warning test is flakey

Created on 11 Aug 2020  ·  3Comments  ·  Source: locustio/locust

I see this very often when running tests locally:

___________________________ TestLocustRunner.test_cpu_warning ___________________________

self = <locust.test.test_runners.TestLocustRunner testMethod=test_cpu_warning>

    def test_cpu_warning(self):
        _monitor_interval = runners.CPU_MONITOR_INTERVAL
        runners.CPU_MONITOR_INTERVAL = 2.0
        try:
            class CpuUser(User):
                wait_time = constant(0.001)
                @task
                def cpu_task(self):
                    for i in range(1000000):
                        _ = 3 / 2
            environment = Environment(user_classes=[CpuUser])
            runner = LocalRunner(environment)
            self.assertFalse(runner.cpu_warning_emitted)
            runner.spawn_users(1, 1, wait=False)
            sleep(2.5)
            runner.quit()
>           self.assertTrue(runner.cpu_warning_emitted)
E           AssertionError: False is not true

test/test_runners.py:121: AssertionError
bug invalid

Most helpful comment

OK I've worked it out: when my Macbook CPU is high the test fails.

I guess that's my problem 😅

All 3 comments

I havent seen that flakyness, neither on my machine (MacOS) or on the Travis runs. Have you tried anything to make it less flaky?

Perhaps the issue is the monitor interval being too long? Try dropping it to 1.0.

Hmmm. Let me test some more and I'll update.

OK I've worked it out: when my Macbook CPU is high the test fails.

I guess that's my problem 😅

Was this page helpful?
0 / 5 - 0 ratings