-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7942372
commit 197e2f0
Showing
3 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import pytest | ||
|
||
from jail import StoppedJail, RunningJail, Jls | ||
|
||
|
||
def start_stop(s): | ||
j = s.start() | ||
j.stop() | ||
|
||
def test_start_stop_jail(benchmark): | ||
s = StoppedJail('/rescue') | ||
|
||
benchmark(start_stop, s) | ||
|
||
|
||
def get_hostname(j): | ||
return j.parameters['host.hostname'] | ||
|
||
def test_get_parameter(benchmark): | ||
s = StoppedJail('/rescue', parameters={'host.hostname': 'test'}) | ||
j = s.start() | ||
hostname = benchmark(get_hostname, j) | ||
assert hostname == 'test' | ||
j.stop() | ||
|
||
|
||
def spawn_hello_world(j): | ||
child = j.spawn(['/echo', 'hello world']) | ||
child.wait() | ||
|
||
def test_spawn(benchmark): | ||
s = StoppedJail('/rescue') | ||
j = s.start() | ||
benchmark(spawn_hello_world, j) | ||
j.stop() | ||
|
||
|
||
import subprocess | ||
def popen_hello_world(j): | ||
child = subprocess.Popen(['/echo', 'hello world'], preexec_fn=lambda: j.attach()) | ||
child.wait() | ||
|
||
def test_popen(benchmark): | ||
s = StoppedJail('/rescue') | ||
j = s.start() | ||
benchmark(popen_hello_world, j) | ||
j.stop() | ||
|
||
def jls_jids(): | ||
return set(j.jid for j in Jls()) | ||
|
||
def test_jls(benchmark): | ||
# start 100 jails | ||
s = StoppedJail('/rescue') | ||
started = [s.start() for _ in range(100)] | ||
started_jids = set(j.jid for j in started) | ||
|
||
jids = benchmark(jls_jids) | ||
|
||
for r in started: | ||
r.stop(); | ||
|
||
assert started_jids <= jids |