Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored test_trace_in_process to be deterministic #25

Merged
merged 1 commit into from
Aug 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 8 additions & 36 deletions tests/unit/tracing/test_trace_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def create_basic_switches(cls, controller):

controller.switches = {dpid_a: mock_switch_a, dpid_b: mock_switch_b}

# Disable pylint message to use the Switch Singleton
# pylint: disable=no-value-for-parameter
Switches()._switches = controller.switches
Switches(MagicMock())._switches = controller.switches

def test_is_entry_invalid(self):
"""Test if the entry request does not have a valid switch."""
Expand Down Expand Up @@ -187,39 +185,13 @@ def test_request_invalid_trace_id(self):
result = self.trace_manager.get_result("1234")
self.assertEqual(result, {"msg": "unknown trace id"})

@patch("napps.amlight.sdntrace.shared.colors.Colors.get_switch_color")
@patch("napps.amlight.sdntrace.tracing.tracer.TracePath.send_trace_probe")
def test_trace_in_process(self, mock_send_probe, mock_colors):
"""Test trace manager tracing request and processing."""
mock_colors.return_value = {
"color_field": "dl_src",
"color_value": "ee:ee:ee:ee:ee:01",
}
mock_send_probe.return_value = {
"dpid": "00:00:00:00:00:00:00:01",
"port": 1,
}, ""

eth = {"dl_vlan": 100}
dpid = {"dpid": "00:00:00:00:00:00:00:01", "in_port": 1}
switch = {"switch": dpid, "eth": eth}
entries = {"trace": switch}

trace_entries = self.trace_manager.is_entry_valid(entries)
self.assertIsInstance(trace_entries, TraceEntries)

trace_id = self.trace_manager.new_trace(trace_entries)
self.assertEqual(trace_id, 30001)

pending = self.trace_manager.number_pending_requests()
self.assertEqual(pending, 1)

while pending == 1:
result = self.trace_manager.get_result(trace_id)
pending = self.trace_manager.number_pending_requests()
time.sleep(0.1)

self.assertEqual(result, {"msg": "trace in process"})
def test_trace_in_process(self):
"""Test trace manager in process."""
self.trace_manager._spawn_trace = MagicMock()
trace_id = 30001
self.trace_manager._running_traces[trace_id] = {}
result = self.trace_manager.get_result(trace_id)
assert result == {"msg": "trace in process"}

@patch("napps.amlight.sdntrace.shared.colors.Colors.get_switch_color")
@patch("napps.amlight.sdntrace.tracing.tracer.TracePath.send_trace_probe")
Expand Down