def test_create_start_destroy_with_context_manager(profile, docker_client): with create(profile.name, 'cat') as sandbox: result = start(sandbox) assert result['stdout'] == b'' result = start(sandbox, stdin=b'stdin data') assert result['stdout'] == b'stdin data' with pytest.raises(docker.errors.NotFound): docker_client.inspect_container(sandbox)
def test_destroy_exited(profile, docker_client): sandbox = create(profile.name, 'true') result = start(sandbox) assert result['exit_code'] == 0 assert docker_client.inspect_container(sandbox) destroy(sandbox) with pytest.raises(docker.errors.NotFound): docker_client.inspect_container(sandbox)
def test_destroy_running(profile, docker_client): sandbox = create(profile.name, 'sleep 10', limits={'realtime': 1}) result = start(sandbox) assert result['timeout'] is True container_info = docker_client.inspect_container(sandbox) assert container_info['State']['Running'] is True destroy(sandbox) with pytest.raises(docker.errors.NotFound): docker_client.inspect_container(sandbox)
def test_destroy_running(profile, docker_client): sandbox = create(profile.name, 'sleep 10', limits={'realtime': 1}) result = start(sandbox) assert result['timeout'] is True container = docker_client.containers.get(sandbox.container.id) assert container.status == 'running' destroy(sandbox) with pytest.raises(docker.errors.NotFound): docker_client.containers.get(sandbox.container.id)
def test_start_same_sandbox_multiple_times(profile): sandbox = create(profile.name, 'cat', limits={'cputime': 20}) expected_result = { 'exit_code': 0, 'stdout': b'', 'stderr': b'', 'duration': ANY, 'timeout': False, 'oom_killed': False, } result = start(sandbox) assert result == expected_result result = start(sandbox, stdin=b'stdin data') assert result == dict(expected_result, stdout=b'stdin data') long_data = b'stdin long data' + b'a b c d e\n' * 100000 result = start(sandbox, stdin=long_data) assert result == dict(expected_result, stdout=long_data) result = start(sandbox) assert result == expected_result
def test_start_with_stdin_data_str(profile): sandbox = create(profile.name, 'cat') result = start(sandbox, stdin="stdin data\n") expected_result = { 'exit_code': 0, 'stdout': b'stdin data\n', 'stderr': b'', 'duration': ANY, 'timeout': False, 'oom_killed': False, } assert result == expected_result assert result['duration'] > 0
def test_start_no_stdin_data(profile): command = 'echo "stdout data" && echo "stderr data" >&2' sandbox = create(profile.name, command) result = start(sandbox) expected_result = { 'exit_code': 0, 'stdout': b'stdout data\n', 'stderr': b'stderr data\n', 'duration': ANY, 'timeout': False, 'oom_killed': False, } assert result == expected_result assert result['duration'] > 0