Skip to content

Commit

Permalink
An improved test for the benchmarker with a program
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Sep 19, 2023
1 parent 4f9ca0c commit c62440e
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions mir-ci/mir_ci/test_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import asyncio
import subprocess
import time
from unittest.mock import Mock

from mir_ci.program import Program
from mir_ci.benchmarker import Benchmarker
Expand Down Expand Up @@ -78,24 +79,19 @@ async def test_program_has_cgroup_file_when_run_with_slice(self) -> None:


class TestBenchmarker:
async def test_benchmarker_with_program(self) -> None:
p = Program(['sh', '-c', 'sleep 1;'])
benchmarker = Benchmarker(p, poll_time_seconds=0.1)
async with benchmarker:
await asyncio.sleep(1)
await p.kill(2)

assert len(benchmarker.get_data()) > 0
assert p.process is not None
if p.process is not None:
assert benchmarker.get_data()[0].pid == p.process.pid
def async_return(self, value):
f = asyncio.Future()
f.set_result(value)
return f

async def test_benchmarker_cpu_has_value(self) -> None:
p = Program(['awk', 'BEGIN{for(i=0;i<100000000;i++){}}'])
async def test_benchmarker_with_program(self) -> None:
p = Mock()
p.__aenter__ = Mock(return_value=self.async_return(True))
p.__aexit__ = Mock(return_value=self.async_return(True))
benchmarker = Benchmarker(p, poll_time_seconds=0.1)
async with benchmarker:
await asyncio.sleep(1)

assert len(benchmarker.get_data()) > 0
assert benchmarker.get_data()[0].max_mem_bytes > 0
assert benchmarker.get_data()[0].cpu_time_microseconds_total > 0
p.get_cgroup.assert_called()
p.__aenter__.assert_called_once()
p.__aexit__.assert_called_once()

0 comments on commit c62440e

Please sign in to comment.