Esempio n. 1
0
    def test_rampup(self):
        with catch_sleep() as delay:

            @scenario(weight=10)
            async def here_three(session):
                _RES.append(3)

            stdout, stderr, rc = self._test_molotov(
                "--ramp-up",
                "10",
                "--workers",
                "5",
                "--console-update",
                "0",
                "-cx",
                "--max-runs",
                "2",
                "-s",
                "here_three",
                "molotov.tests.test_run",
            )
            # workers should start every 2 seconds since
            # we have 5 workers and a ramp-up
            # the first one starts immediatly, then each worker
            # sleeps 2 seconds more.
            delay = [d for d in delay if d != 0]
            self.assertEqual(delay, [1, 2.0, 4.0, 6.0, 8.0, 1, 1])
            wanted = "SUCCESSES: 10"
            self.assertTrue(wanted in stdout, stdout)
Esempio n. 2
0
    def test_sizing(self):
        _RES2["fail"] = 0
        _RES2["succ"] = 0

        with catch_sleep():

            @scenario()
            async def sizer(session):
                if random.randint(0, 20) == 1:
                    _RES2["fail"] += 1
                    raise AssertionError()
                else:
                    _RES2["succ"] += 1

            stdout, stderr, rc = self._test_molotov(
                "--sizing",
                "--console-update",
                "0",
                "--sizing-tolerance",
                "5",
                "-s",
                "sizer",
                "molotov.tests.test_run",
            )

        ratio = float(_RES2["fail"]) / float(_RES2["succ"]) * 100.0
        self.assertTrue(ratio < 14.75 and ratio >= 4.75, ratio)
        found = re.findall(r"obtained with (\d+) workers", stdout)
        assert int(found[0]) > 50
Esempio n. 3
0
    def test_sizing_multiprocess(self):
        counters = SharedCounters('OK', 'FAILED')

        with catch_sleep():
            @scenario()
            async def sizer(session):
                if random.randint(0, 10) == 1:
                    counters['FAILED'] += 1
                    raise AssertionError()
                else:
                    counters['OK'] += 1

            with set_args('molotov', '--sizing', '-p', '2',
                          '--sizing-tolerance', '5',
                          '--console-update', '0',
                          '-s', 'sizer',
                          'molotov.tests.test_run') as (stdout, stderr):
                try:
                    main()
                except SystemExit:
                    pass
            stdout, stderr = stdout.read().strip(), stderr.read().strip()

            # stdout, stderr, rc = self._test_molotov()
            ratio = (float(counters['FAILED'].value) /
                     float(counters['OK'].value) * 100.)
            self.assertTrue(ratio >= 5., ratio)
Esempio n. 4
0
    def test_sizing_multiprocess(self):
        counters = SharedCounters('OK', 'FAILED')

        with catch_sleep():
            @scenario()
            async def sizer(session):
                if random.randint(0, 10) == 1:
                    counters['FAILED'] += 1
                    raise AssertionError()
                else:
                    counters['OK'] += 1

            with set_args('molotov', '--sizing', '-p', '2',
                          '--sizing-tolerance', '5',
                          '--console-update', '0',
                          '-s', 'sizer',
                          'molotov.tests.test_run') as (stdout, stderr):
                try:
                    main()
                except SystemExit:
                    pass
            stdout, stderr = stdout.read().strip(), stderr.read().strip()

            # stdout, stderr, rc = self._test_molotov()
            ratio = (float(counters['FAILED'].value) /
                     float(counters['OK'].value) * 100.)
            self.assertTrue(ratio >= 5., ratio)
Esempio n. 5
0
    def test_single_run(self):
        _RES = defaultdict(int)

        with catch_sleep():

            @scenario()
            async def one(session):
                _RES["one"] += 1

            @scenario()
            async def two(session):
                _RES["two"] += 1

            @scenario()
            async def three(session):
                _RES["three"] += 1

            stdout, stderr, rc = self._test_molotov(
                "--single-run",
                "molotov.tests.test_run",
            )

        assert rc == 0
        assert _RES["one"] == 1
        assert _RES["two"] == 1
        assert _RES["three"] == 1
Esempio n. 6
0
    def test_bug_121(self):

        PASSED = [0]

        with catch_sleep():

            @scenario()
            async def scenario_one(session):

                cookies = {
                    "csrftoken": "sometoken",
                    "dtk": "1234",
                    "djdt": "hide",
                    "sessionid": "5678",
                }
                boundary = "----WebKitFormBoundaryFTE"
                headers = {
                    "X-CSRFToken":
                    "sometoken",
                    "Content-Type":
                    "multipart/form-data; boundary={}".format(boundary),
                }
                data = json.dumps({"1": "xxx"})

                with aiohttp.MultipartWriter("form-data",
                                             boundary=boundary) as mpwriter:
                    mpwriter.append(
                        data,
                        {
                            "Content-Disposition":
                            'form-data; name="json"; filename="blob"',
                            "Content-Type": "application/json",
                        },
                    )
                    async with session.post(
                            "http://localhost:8888",
                            data=mpwriter,
                            headers=headers,
                            cookies=cookies,
                    ) as resp:
                        res = await resp.text()
                        assert data in res
                        PASSED[0] += 1

            args = self._get_args()
            args.verbose = 2
            args.max_runs = 1
            with coserver():
                res = run(args)

            assert PASSED[0] == 1
            assert res["OK"] == 1
Esempio n. 7
0
    def test_delay(self):
        with catch_sleep() as delay:
            @scenario(weight=10, delay=.1)
            async def here_three(session):
                _RES.append(3)

            stdout, stderr, rc = self._test_molotov('--delay', '.6',
                                                    '--console-update', '0',
                                                    '-cx', '--max-runs', '2',
                                                    '-s', 'here_three',
                                                    'molotov.tests.test_run')
            wanted = "SUCCESSES: 2"
            self.assertTrue(wanted in stdout, stdout)
            self.assertEqual(delay, [10, 1, .1, 1, .6, 1, .1, 1, .6, 1])
Esempio n. 8
0
    def test_delay(self):
        with catch_sleep() as delay:
            @scenario(weight=10, delay=.1)
            async def here_three(session):
                _RES.append(3)

            stdout, stderr, rc = self._test_molotov('--delay', '.6',
                                                    '--console-update', '0',
                                                    '-cx', '--max-runs', '2',
                                                    '-s', 'here_three',
                                                    'molotov.tests.test_run')
            wanted = "SUCCESSES: 2"
            self.assertTrue(wanted in stdout, stdout)
            self.assertEqual(delay, [1, .1, 1, .6, 1, .1, 1, .6, 1])
Esempio n. 9
0
    def xxx_test_disable_dns(self, m_resolve):

        with catch_sleep():

            @scenario()
            async def one(session):
                async with session.get("http://localhost"):
                    pass

            stdout, stderr, rc = self._test_molotov(
                "--disable-dns-resolve",
                "--single-run",
                "molotov.tests.test_run",
            )

        m_resolve.assert_not_called()
Esempio n. 10
0
    def test_timed_sizing(self):
        _RES2["fail"] = 0
        _RES2["succ"] = 0
        _RES2["messed"] = False

        with catch_sleep():

            @scenario()
            async def sizer(session):
                if get_context(
                        session).worker_id == 200 and not _RES2["messed"]:
                    # worker 2 will mess with the timer
                    # since we're faking all timers, the current
                    # time in the test is always around 0
                    # so to have now() - get_timer() > 60
                    # we need to set a negative value here
                    # to trick it
                    set_timer(-61)
                    _RES2["messed"] = True
                    _RES2["fail"] = _RES2["succ"] = 0

                if get_context(session).worker_id > 100:
                    # starting to introduce errors passed the 100th
                    if random.randint(0, 10) == 1:
                        _RES2["fail"] += 1
                        raise AssertionError()
                    else:
                        _RES2["succ"] += 1

                # forces a switch
                await asyncio.sleep(0)

            stdout, stderr, rc = self._test_molotov(
                "--sizing",
                "--sizing-tolerance",
                "5",
                "--console-update",
                "0",
                "-cs",
                "sizer",
                "molotov.tests.test_run",
            )

        ratio = float(_RES2["fail"]) / float(_RES2["succ"]) * 100.0
        self.assertTrue(ratio < 20.0 and ratio > 4.75, ratio)
Esempio n. 11
0
    def _XXX_test_enable_dns(self, m_resolve):

        m_resolve.return_value = ("http://localhost", "http://localhost",
                                  "localhost")

        with catch_sleep():

            @scenario()
            async def one(session):
                async with session.get("http://localhost"):
                    pass

            stdout, stderr, rc = self._test_molotov(
                "--single-run",
                "molotov.tests.test_run",
            )

        m_resolve.assert_called()
Esempio n. 12
0
    def test_rampup(self):
        with catch_sleep() as delay:
            @scenario(weight=10)
            async def here_three(session):
                _RES.append(3)

            stdout, stderr, rc = self._test_molotov('--ramp-up', '10',
                                                    '--workers', '5',
                                                    '--console-update', '0',
                                                    '-cx', '--max-runs', '2',
                                                    '-s', 'here_three',
                                                    'molotov.tests.test_run')
            # workers should start every 2 seconds since
            # we have 5 workers and a ramp-up
            # the first one starts immediatly, then each worker
            # sleeps 2 seconds more.
            delay = [d for d in delay if d != 0]
            self.assertEqual(delay, [1, 2.0, 4.0, 6.0, 8.0, 1, 1])
            wanted = "SUCCESSES: 10"
            self.assertTrue(wanted in stdout, stdout)
Esempio n. 13
0
    def test_sizing(self):
        _RES2['fail'] = 0
        _RES2['succ'] = 0

        with catch_sleep():
            @scenario()
            async def sizer(session):
                if random.randint(0, 20) == 1:
                    _RES2['fail'] += 1
                    raise AssertionError()
                else:
                    _RES2['succ'] += 1

            stdout, stderr, rc = self._test_molotov('--sizing',
                                                    '--console-update', '0',
                                                    '--sizing-tolerance', '5',
                                                    '-s', 'sizer',
                                                    'molotov.tests.test_run')

        ratio = float(_RES2['fail']) / float(_RES2['succ']) * 100.
        self.assertTrue(ratio < 15. and ratio >= 5., ratio)
Esempio n. 14
0
    def test_sizing(self):
        _RES2['fail'] = 0
        _RES2['succ'] = 0

        with catch_sleep():
            @scenario()
            async def sizer(session):
                if random.randint(0, 20) == 1:
                    _RES2['fail'] += 1
                    raise AssertionError()
                else:
                    _RES2['succ'] += 1

            stdout, stderr, rc = self._test_molotov('--sizing',
                                                    '--console-update', '0',
                                                    '--sizing-tolerance', '5',
                                                    '-s', 'sizer',
                                                    'molotov.tests.test_run')

        ratio = float(_RES2['fail']) / float(_RES2['succ']) * 100.
        self.assertTrue(ratio < 15. and ratio >= 5., ratio)
Esempio n. 15
0
    def test_delay(self):
        with catch_sleep() as delay:

            @scenario(weight=10, delay=0.1)
            async def here_three(session):
                _RES.append(3)

            stdout, stderr, rc = self._test_molotov(
                "--delay",
                ".6",
                "--console-update",
                "0",
                "-cx",
                "--max-runs",
                "2",
                "-s",
                "here_three",
                "molotov.tests.test_run",
            )
            wanted = "SUCCESSES: 2"
            self.assertTrue(wanted in stdout, stdout)
            self.assertEqual(delay[:9], [1, 0.1, 1, 0.6, 1, 0.1, 1, 0.6, 1])
Esempio n. 16
0
    async def test_step(self, loop, console, results):
        res = []

        @scenario(weight=0)
        async def test_one(session):
            res.append("1")

        @scenario(weight=100, delay=1.5)
        async def test_two(session):
            res.append("2")

        async def _slept(time):
            res.append(time)

        w = self.get_worker(console, results, loop=loop)

        with catch_sleep(res):
            async with LoggedClientSession(loop, console) as session:
                result = await w.step(0, session)
                self.assertTrue(result, 1)
                self.assertEqual(len(res), 2)
                self.assertEqual(res[1], 1.5)
Esempio n. 17
0
    def test_timed_sizing(self):
        _RES2['fail'] = 0
        _RES2['succ'] = 0
        _RES2['messed'] = False

        with catch_sleep():

            @scenario()
            async def sizer(session):
                if session.worker_id == 200 and not _RES2['messed']:
                    # worker 2 will mess with the timer
                    # since we're faking all timers, the current
                    # time in the test is always around 0
                    # so to have now() - get_timer() > 60
                    # we need to set a negative value here
                    # to trick it
                    set_timer(-61)
                    _RES2['messed'] = True
                    _RES2['fail'] = _RES2['succ'] = 0

                if session.worker_id > 100:
                    # starting to introduce errors passed the 100th
                    if random.randint(0, 10) == 1:
                        _RES2['fail'] += 1
                        raise AssertionError()
                    else:
                        _RES2['succ'] += 1

                # forces a switch
                await asyncio.sleep(0)

            stdout, stderr, rc = self._test_molotov('--sizing',
                                                    '--sizing-tolerance', '5',
                                                    '--console-update', '0',
                                                    '-cs', 'sizer',
                                                    'molotov.tests.test_run')

        ratio = float(_RES2['fail']) / float(_RES2['succ']) * 100.
        self.assertTrue(ratio < 20. and ratio > 5., ratio)
Esempio n. 18
0
    def test_timed_sizing(self):
        _RES2['fail'] = 0
        _RES2['succ'] = 0
        _RES2['messed'] = False

        with catch_sleep():
            @scenario()
            async def sizer(session):
                if session.worker_id == 200 and not _RES2['messed']:
                    # worker 2 will mess with the timer
                    # since we're faking all timers, the current
                    # time in the test is always around 0
                    # so to have now() - get_timer() > 60
                    # we need to set a negative value here
                    # to trick it
                    set_timer(-61)
                    _RES2['messed'] = True
                    _RES2['fail'] = _RES2['succ'] = 0

                if session.worker_id > 100:
                    # starting to introduce errors passed the 100th
                    if random.randint(0, 10) == 1:
                        _RES2['fail'] += 1
                        raise AssertionError()
                    else:
                        _RES2['succ'] += 1

                # forces a switch
                await asyncio.sleep(0)

            stdout, stderr, rc = self._test_molotov('--sizing',
                                                    '--sizing-tolerance', '5',
                                                    '--console-update', '0',
                                                    '-cs', 'sizer',
                                                    'molotov.tests.test_run')

        ratio = float(_RES2['fail']) / float(_RES2['succ']) * 100.
        self.assertTrue(ratio < 20. and ratio > 5., ratio)
Esempio n. 19
0
    def test_sizing_multiprocess(self):
        counters = SharedCounters("OK", "FAILED")

        with catch_sleep():

            @scenario()
            async def sizer(session):
                if random.randint(0, 10) == 1:
                    counters["FAILED"] += 1
                    raise AssertionError()
                else:
                    counters["OK"] += 1

            with set_args(
                    "molotov",
                    "--sizing",
                    "-p",
                    "2",
                    "--sizing-tolerance",
                    "5",
                    "--console-update",
                    "0",
                    "-s",
                    "sizer",
                    "molotov.tests.test_run",
            ) as (stdout, stderr):
                try:
                    main()
                except SystemExit:
                    pass
            stdout, stderr = stdout.read().strip(), stderr.read().strip()

            # stdout, stderr, rc = self._test_molotov()
            ratio = (float(counters["FAILED"].value) /
                     float(counters["OK"].value) * 100.0)
            self.assertTrue(ratio >= 4.75, ratio)