Testing out Coverage.py In-flight Save
We'll run four servers which we interact with via curl
:
$ make run
main(): <coverage.control.Coverage object at 0x10d3ce3c8>
p() running in thread Thread-1: <coverage.control.Coverage object at 0x10d3ce3c8>
q() running in thread Thread-2: <coverage.control.Coverage object at 0x10d3ce3c8>
r() running in process Process-1: <coverage.control.Coverage object at 0x10d4e94e0>
s() running in process Process-2: <coverage.control.Coverage object at 0x10d7257b8>
...
In another shell, we can invoke the routes used to save without shutting down any of the servers:
$ ./invoke.sh
+ curl localhost:8000/noop
+ sleep 0.05
+ curl localhost:8001/save
+ sleep 0.05
+ curl localhost:8000/save
+ sleep 0.05
+ curl localhost:8002/save
+ sleep 0.05
+ curl localhost:8002/save
+ sleep 0.05
+ curl localhost:8003/save
+ sleep 0.05
+ curl localhost:8003/save
+ sleep 0.05
which results in
$ make run
...
s() running in process Process-2: <coverage.control.Coverage object at 0x10d7257b8>
8000 | p() | /noop
8001 | q() | /save
Saving coverage in q(): <coverage.control.Coverage object at 0x10d3ce3c8>
8000 | p() | /save
Saving coverage in p(): <coverage.control.Coverage object at 0x10d3ce3c8>
8002 | r() | /save
Saving coverage in r(): <coverage.control.Coverage object at 0x10d4e94e0>
8002 | r() | /save
Saving coverage in r(): <coverage.control.Coverage object at 0x10d4e94e0>
8003 | s() | /save
Saving coverage in s(): <coverage.control.Coverage object at 0x10d7257b8>
8003 | s() | /save
Saving coverage in s(): <coverage.control.Coverage object at 0x10d7257b8>
...
The /save
calls in the multiprocessing.Process
workers end up producing
2 extra files:
$ ls -1 coverage-report.bin*
coverage-report.bin.${hostname}.4837.526273
coverage-report.bin.${hostname}.4840.757112
coverage-report.bin.${hostname}.4841.949654
and the report that reflects the fact that we've hit the lines for the server other than shutdown and process cleanup:
$ make report
Name Stmts Miss Branch BrPart Cover Missing
-----------------------------------------------------
main.py 70 9 6 2 86% 19-20, 22->23, 23, 89-95, 98->exit
If we shutdown the servers
$ ./shutdown.sh
+ curl localhost:8000/shutdown
+ curl localhost:8001/shutdown
+ curl localhost:8002/shutdown
+ curl localhost:8003/shutdown
the process will exit with
$ make run
...
Saving coverage in s(): <coverage.control.Coverage object at 0x10d7257b8>
8000 | p() | /shutdown
8001 | q() | /shutdown
8002 | r() | /shutdown
8003 | s() | /shutdown
Coverage.py warning: No data was collected. (no-data-collected)
and we see 3 newly saved reports next to the previously generated (via
coverage combine
) report:
$ ls -1 coverage-report.bin*
coverage-report.bin
coverage-report.bin.${hostname}.4837.526273
coverage-report.bin.${hostname}.4840.757112
coverage-report.bin.${hostname}.4841.949654
However, two of the reports have no data
$ du -h coverage-report.bin.*
0B coverage-report.bin.${hostname}.4840.757112
0B coverage-report.bin.${hostname}.4841.949654