Skip to content

Commit

Permalink
observer: Basic nose tests using static PCAP files
Browse files Browse the repository at this point in the history
  • Loading branch information
irl committed Oct 11, 2016
1 parent 9cdd1a7 commit e9c7f7f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
23 changes: 0 additions & 23 deletions pathspider/observer/__init__.py
Expand Up @@ -450,26 +450,3 @@ def simple_observer(lturi):
ip4_chain=[basic_count],
ip6_chain=[basic_count])

def test_observer(lturi):
import threading

logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)

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

logging.getLogger().info("test observer received "+str(flowcount)+" flows")


41 changes: 41 additions & 0 deletions tests/test_observer.py
@@ -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 added tests/testdata/random.pcap
Binary file not shown.
Binary file added tests/testdata/real.pcap
Binary file not shown.

0 comments on commit e9c7f7f

Please sign in to comment.