Commit Graph

60 Commits

Author SHA1 Message Date
R W H Bricheno df61f6ab4d Prevent MacOS exception on shutdown of closed socket. 2018-03-19 21:58:27 +05:45
R W H Bricheno 39f325af3e Fix getting the directory path on Mac OS X. 2018-03-19 21:58:27 +05:45
Alex Willmer 026669aa93 tests: Fix GetModuleViaPkgutilTest fetching .pyc
On my laptop (Ubuntu 17.10, Python 2.7.14 in a virtualenv),
`test_regular_mod` fails with

```
AssertionError: "\nimport sys\n\n\ndef say_hi():\n    print 'hi'\n" !=
'\x03\xf3\r\n\xbbW\xd5Yc\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00@\x00\x00\x00s\x19\x00\x00\x00d\x00\x00d\x01\x00l\x00\x00Z\x00\x00d\x02\x00\x84\x00\x00Z\x01\x00d\x01\x00S(\x03\x00\x00\x00i\xff\xff\xff\xffNc\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00C\x00\x00\x00s\t\x00\x00\x00d\x01\x00GHd\x00\x00S(\x02\x00\x00\x00Nt\x02\x00\x00\x00hi(\x00\x00\x00\x00(\x00\x00\x00\x00(\x00\x00\x00\x00(\x00\x00\x00\x00sF\x00\x00\x00/home/alex/src/mitogen/tests/data/module_finder_testmod/regular_mod.pyt\x06\x00\x00\x00say_hi\x05\x00\x00\x00s\x02\x00\x00\x00\x00\x01(\x02\x00\x00\x00t\x03\x00\x00\x00sysR\x01\x00\x00\x00(\x00\x00\x00\x00(\x00\x00\x00\x00(\x00\x00\x00\x00sF\x00\x00\x00/home/alex/src/mitogen/tests/data/module_finder_testmod/regular_mod.pyt\x08\x00\x00\x00<module>\x02\x00\x00\x00s\x02\x00\x00\x00\x0c\x03'
```

`__file__` contains the path of the compiled `.pyc`, not the `.py`
source file.
2018-03-19 21:58:27 +05:45
David Wilson 65defaa354 tests: initial first_stage_test. 2018-03-19 21:58:27 +05:45
Alex Willmer 8dcfb1b7f7 testlib: Auto negotiate Docker API version
Ubuntu 17.04 provides Docker 1.12.6, which has API version 1.24.
`dev_requirements.txt` specifies the docker-py 2.5.1, which by default
requests API version 1.30.

Hence when the SSH unit tests try to run the container specified in
`DockerizedSshDaemon` an error occurs

```
APIError: 400 Client Error: Bad Request ("client is newer than server
(client API version: 1.30, server API version: 1.24)")
```
2018-03-19 21:58:27 +05:45
Alex Willmer 94992940dd ssh_test: Correct hostname in SShTest.test_stream_name()
I presume that `u1704` is a relic of a bygone container/host.
2018-03-19 21:58:27 +05:45
Alex Willmer dfc7b85504 testlib: Wait for sshd before running tests
On Ubuntu 17.10 something (probably Docker) appears to be accepting
connections, before sshd is fully ready. This results in a race
condition, and hence connection errors for the first few tests (2-3 on
my laptop).

testlib.wait_for_port() checks not only that the port can be connected
to, but also something resembling the sshd banner is sent.

Fixes #51
2018-03-19 21:58:27 +05:45
David Wilson f8a84616d7 tests: stop responder_test spamming the logs 2018-03-19 21:58:27 +05:45
David Wilson 7389272dc4 tests: stop fakessh spamming the logs 2018-03-19 21:58:27 +05:45
David Wilson 828f60351b importer: Delete _get_module_via_parent entirely
Can't figure out what it's supposed to do any more, and can't find a
version of Ansible before August 2016 (when I wrote that code) that
seems to need it.

Add some more mitigations to avoid sending dylibs.
2018-03-19 21:58:27 +05:45
David Wilson 17a05dc14f Try to be compatible with older Docker daemons; (hopefully) closes #46 2018-03-19 21:35:37 +05:45
David Wilson b7a9aa46cf core: More robust shutdown
Now there is a separate SHUTDOWN message that relies only on being
received by the broker thread, the main thread can be hung horribly and
the process will still eventually receive a SIGTERM.
2018-03-19 21:35:37 +05:45
David Wilson 32d029ed75 Add test that hangs the main thread during shutdown. 2018-03-19 21:35:37 +05:45
David Wilson 3285fc2f75 Implement test_aborted_on_local_context_disconnect 2018-03-19 21:35:37 +05:45
David Wilson dfe68b33d6 Handle docker running on localhost. 2018-03-19 21:35:37 +05:45
David Wilson bee1a86aa1 Let utils_test run directly too. 2018-03-19 21:35:37 +05:45
David Wilson 690ee6dbe2 Fix select_test failure, remove crap old timing_test. 2018-03-19 21:35:37 +05:45
David Wilson 9c8ff7ecf6 Remove proxy_test (duplicates sudo_test) 2018-03-19 21:35:37 +05:45
David Wilson f22d05a7ad frameworkize nested_test. 2018-03-19 21:35:37 +05:45
David Wilson 15bf0f54e2 Beginnings of module_finder_test 2018-03-19 21:35:37 +05:45
David Wilson d17af194b5 Fix importer_test constructor signature. 2018-03-19 21:35:37 +05:45
David Wilson 2454dcc990 core: loosen assertion to allow fakessh_test to succeed. 2018-03-19 21:35:37 +05:45
David Wilson bc801bc2ed Allow call_function_test to succeed depite testlib import. 2018-03-19 21:35:37 +05:45
David Wilson 118fe01be5 Use enhanced assertRaises in call_function_test.py. 2018-03-19 21:35:37 +05:45
David Wilson 9b13a4cc61 Fix 2 call_function_test failures. 2018-03-19 21:35:37 +05:45
David Wilson 236d83418c Simple scan_code_imports test. 2018-03-19 21:35:37 +05:45
David Wilson af6812b458 Fix context naming for sudo and via=. 2018-03-19 21:35:37 +05:45
David Wilson 1449c972eb Allow running responder_test with unittest. 2018-03-19 21:35:36 +05:45
David Wilson 849ccebe04 receiver: only permit one notify callback
There is no point spamming a list for every function call, there is no
use case where multiple notify callbacks would be useful.
2018-03-19 21:35:36 +05:45
David Wilson bcae62c682 issue #20: TestCase subclass with a nicer assertRaises 2018-03-19 21:35:36 +05:45
David Wilson f869e088f8 issue #20: tests and fixes for mitogen.master.Select(). 2018-03-19 21:35:36 +05:45
David Wilson ced6d8e404 Fix up importer_test. 2018-03-19 21:35:36 +05:45
David Wilson 40e2e6eb4c Add README.md to tests subdir. 2018-03-19 21:35:36 +05:45
David Wilson 2fed3613e9 Syntax error. 2018-03-19 21:35:36 +05:45
Alex Willmer d706b7d6b8 Update lingering references to with_broker & run_with_broker
A previous commit renamed run_with_broker() and with_broker() to
run_with_router() and with_router() respctively. Some references were
missed.
2018-03-19 21:35:36 +05:45
David Wilson 1510b72a25 fakessh: Add integration test for inter-child rsync. 2018-03-19 21:35:35 +05:45
David Wilson f01e457d70 Allow running without py.test. 2018-03-19 21:35:35 +05:45
David Wilson 750e9fab24 Make log_to_file accept string level rather than logging package constant
Saves an import, pain in the ass to type all the time.
2018-03-19 21:35:35 +05:45
David Wilson 1411790f56 master: make write_all() handle O_NONBLOCK and deadlines. 2018-03-19 21:35:35 +05:45
David Wilson db225638f0 core: Make iter_read() handle deadline (and non-blocking IO) properly 2018-03-19 21:35:35 +05:45
David Wilson 3c8c1f71a6 Update test. 2018-03-19 21:35:35 +05:45
David Wilson 5dff221842 fakessh: cleanup master test. 2018-03-19 21:35:35 +05:45
David Wilson c67119501b Keep allocate_id() in the enhanced router class. 2018-03-19 21:35:35 +05:45
David Wilson 4720eb1c55 core: add ALLOCATE_ID message for fakessh. 2018-03-19 21:35:35 +05:45
David Wilson 502266f115 Fix Channel constructor and add simple test; closes #32 2018-03-19 21:35:35 +05:45
David Wilson 3a0f03183c Simple working fakessh_test. 2018-03-19 21:35:35 +05:45
David Wilson 498f961488 Fix up a few more ssh_tests, stop sending 400 modules over network.
Defining functions in the current module was causing the entirety of
py.test and all dependencies to be sucked in.
2018-03-19 21:35:35 +05:45
David Wilson f04a503caa Add rsync and git to build_docker_image too. 2018-03-19 21:35:35 +05:45
David Wilson e2d3ac9b6a Fixup some more tests. 2018-03-19 21:35:35 +05:45
David Wilson 2736592c79 First handful of functional tests for SSH against Docker. 2018-03-19 21:35:34 +05:45