Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
observer: Basic nose tests using static PCAP files
- Loading branch information
Showing
4 changed files
with
41 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
import logging | ||
import queue | ||
import threading | ||
|
||
import nose | ||
|
||
from pathspider.base import SHUTDOWN_SENTINEL | ||
from pathspider.observer import simple_observer | ||
|
||
def _test_observer(lturi): | ||
try: | ||
import plt # libtrace may not be available | ||
except: | ||
raise nose.SkipTest | ||
|
||
logging.getLogger().setLevel(logging.INFO) | ||
|
||
o = simple_observer(lturi) | ||
q = queue.Queue() | ||
t = threading.Thread(target=o.run_flow_enqueuer, | ||
args=(q,), | ||
daemon=True) | ||
t.start() | ||
|
||
flowcount = 0 | ||
while True: | ||
f = q.get() | ||
if f == SHUTDOWN_SENTINEL: | ||
break | ||
flowcount += 1 | ||
|
||
return flowcount | ||
|
||
def test_observer_random_flowcount(): | ||
lturi = "pcap:tests/testdata/random.pcap" | ||
assert _test_observer(lturi) == 0 | ||
|
||
def test_observer_real_flowcount(): | ||
lturi = "pcap:tests/testdata/real.pcap" | ||
assert _test_observer(lturi) == 6342 |
Binary file not shown.
Binary file not shown.