Commit Graph

1024 Commits (master)

Author SHA1 Message Date
Alex Willmer 7b8fef5284 tests: Make the tests directory an importable package
Required for test discovery by e.g. unit2, pytest
6 years ago
Alex Willmer a22294dda9 call_function_test: Fix assumption that we run as a script 6 years ago
Alex Willmer 0dcaeb21a2 master_test: Don't assume __file__ points to source code
When run under a test runner the unit tests are imported as modules.
This triggers .pyc generation, after which __file__ resolves to the .pyc
file.
6 years ago
Alex Willmer 841c2b13a1 fakessh_test: Apply timeout decorators to rsync tests
timeoutcontext.timeout uses SIGALRM, hence it will only work on Unix
like operating systems.
6 years ago
Alex Willmer 48623763d6 minimize_source: Implement reindentation 6 years ago
Alex Willmer 556ee2aec6 minimize_source: Handling indentation
In the case that string(s) are replaced, any indent or dedent tags must
be re-inserted after the replacemnts.
6 years ago
Alex Willmer 36c5ff1d05 minimize_source: Make comments test invariant on hashbang/coding handling
strip_comments() currently ignores comments on lines 1 and 2, in order
to preserve lines such as

The comments test had normal comments on those lines, hence it was
failing.
6 years ago
Alex Willmer 3bf61bb311 tests: Clarify which minimize_source samples are the reference 6 years ago
Alex Willmer 35ae4e4227 Issue #160: Add minimize_source testcases 6 years ago
David Wilson bbb0f1bbd8 issue #155: fix double-fork behaviour and test it this time. 6 years ago
David Wilson 4c433dbed1 parent_test: Add explanation. 6 years ago
David Wilson bde1778373 tests: merge tty_create_child() test into parent_test and fix hang 6 years ago
David Wilson 6670cba41c Introduce handler policy functions; closes #138.
Now you can specify a function to add_handler() that authenticates the
message header, with has_parent_authority() and is_immediate_child()
built in.
6 years ago
David Wilson f726ef86de tests: first_stage_test regression due to 1ff27ada49 6 years ago
David Wilson 40b978c9b7 core: Fix source verification.
Previously:

* src_id could be spoofed
* auth_id was checked but the message was still delivered!
6 years ago
David Wilson fe614aa966 core: cleanup handlers on broker crash; closes #112. 6 years ago
David Wilson 1ff27ada49 Add maximum message size checks. Closes #151. 6 years ago
David Wilson 80a97fbc9b core: Rename Sender.put() to Sender.send().
Been annoying me for months.
6 years ago
David Wilson 085b3d21bd core: fix call_function_test regression
Second time in 3 weeks. So stupid. This time write tests.
6 years ago
David Wilson 0f29baa077 core: support pickling senders, Receiver.to_sender()
CC @moreati, in case this impacts you
6 years ago
David Wilson 17aef51e6e tests: Import .local() latency test 6 years ago
David Wilson a8a31728a0 tests: Import Latch soak test 6 years ago
David Wilson 03fcf057dd tests: just call log_to_file() from testlib
Now we can run test.sh with MITOGEN_LOG_LEVEL=debug and things just
work.
6 years ago
David Wilson 761cd9eaf8 tests: import tty_create_child_test.py. 6 years ago
David Wilson 7b12f84366 core: support CallError(str) for service.py. 6 years ago
David Wilson fccca54068 tests: ensure OpenSSL is initialized prior to test. 6 years ago
David Wilson 4903052f42 fork: reseed Python/SSL PRNGs
Mac's SSL seems to have a pthread_atfork handler or similar that does
this for us, no clue if Linux is the same.
6 years ago
David Wilson 48351a1889 issue #155: parent: support Context.shutdown(), reap children on exit.
This permits graceful shutdown of individual contexts, without tearing
down everything.

Update mitogen.parent.Stream to also wait for the child to exit, to
prevent the buildup of zombie processes. This introduces a blocking wait
for process exit on the Broker thread, let's see if we can get away with
it. Chances are reasonable that it'll cause needless hangs on heavily
loaded machines.
6 years ago
David Wilson 4f93c6823a issue #155: skeletal fork_test. 6 years ago
David Wilson 2d7821b824 tests: test_stream_name: fix non-localhost Docker 6 years ago
David Wilson 23e279b617 tests: get import_test limping back to health. 6 years ago
David Wilson f4ba66e3ee issue #155: allocate child IDs in batches of 1000.
Avoids a roundtrip for every fork.
6 years ago
David Wilson 2132c311b2 tests: mark some tests as skipped 6 years ago
David Wilson 8aada2646c core: support throwing LatchError in every sleeping thread
This is to allow Select() to be used as a generic queueing primitive
that supports graceful shutdown.
6 years ago
Alex Willmer e3b700b553 tests: Fix no such option -o running FakeSsh.test_okay()
Full output of failed test

```
ERROR: test_okay (__main__.FakeSshTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/ssh_test.py", line 16, in test_okay
    ssh_path=testlib.data_path('fakessh.py'),
  File "/home/alex/src/mitogen/mitogen/master.py", line 650, in ssh
    return self.connect('ssh', **kwargs)
  File "/home/alex/src/mitogen/mitogen/parent.py", line 463, in connect
    return self._connect(context_id, klass, name=name, **kwargs)
  File "/home/alex/src/mitogen/mitogen/parent.py", line 449, in _connect
    stream.connect()
  File "/home/alex/src/mitogen/mitogen/ssh.py", line 104, in connect
    super(Stream, self).connect()
  File "/home/alex/src/mitogen/mitogen/parent.py", line 395, in connect
    self._connect_bootstrap()
  File "/home/alex/src/mitogen/mitogen/ssh.py", line 116, in
_connect_bootstrap
    time.time() + 10.0):
  File "/home/alex/src/mitogen/mitogen/parent.py", line 207, in
iter_read
    (''.join(bits)[-300:],)
mitogen.core.StreamError: EOF on stream; last 300 bytes received:
'Usage: fakessh.py [options]\n\nfakessh.py: error: no such option: -o\n'
```
6 years ago
Alex Willmer 0f82f68fee parent: Precompute preamble sizes for first stage
SSH command size: 453 (no change)
Preamble size: 8941 (-5 bytes)
6 years ago
Alex Willmer b433645d11 tests: Fix import error 6 years ago
Alex Willmer c6f3bfd93a tests: Correct path to apply_mode_spec() 6 years ago
David Wilson 23f78ca5a2 README: move testing bits into tests directory. 6 years ago
David Wilson f5b5e4849e tests: import very basic latch_test 6 years ago
David Wilson f6d87faf37 tests: import ansible_helpers_test. 6 years ago
Alex Willmer 4b373c421b core: Standardise type of Importer.whitelist
This seemed a reasonable streamlining, but I'm happy to be overruled.
6 years ago
Alex Willmer 8338caa419 tests: Add mitogen.core.is_blacklisted_import() tests
These test the current behviour, which may not be exactly the intended
behaviour. Refs #98
6 years ago
Alex Willmer 491355548d tests: Fix typo in ResolveRelPathTest 6 years ago
Alex Willmer ef35d55523 tests: Remove jinja2/markupsafe modules from FindRelatedTest
Not sure how they got there, but Django doesn't use Jinja without
explicit configuration.
6 years ago
Alex Willmer eee312a57e tests: Fix expected values FindRelatedTest for Django 1.11.4 6 years ago
Alex Willmer 4424bfbb7a tests: Add new FindRelatedImportsTest 6 years ago
Alex Willmer 9e43f5e6ba tests: Remove module under search from expected results
This matches a tweak made in 8765f761c9
6 years ago
Alex Willmer 0f9bfc1e21 tests: Rename FindRelatedImportsTest -> FindRelatedTest 6 years ago
David Wilson afc8697288 core: Ensure add_handler() callbacks really receive _DEAD on shutdown 6 years ago
David Wilson ccd9c62399 tests: stubs for future whitelist/blacklist tests. 6 years ago
Alex Willmer f4405c6bbc Split IterReadTest & WriteAllTest into test_parent
This matches their respective functions under test, which now reside in
mitogen.parent.
6 years ago
Alex Willmer 4fb1b928b7 Adjust unittest for master -> parent split
Tests should now match changes in
4d31300dd0
6 years ago
Alex Willmer 9ccff0f5d1 Fix TypeError while initiliazing ImporterMixin
Since f44356af32 mitogen.core.Importer()
takes a Router instance.
6 years ago
Alex Willmer fa0f390d4d FIx syntax error in FindRelatedImportsTest.test_django_db_models 6 years ago
David Wilson dd088908df select: clean up API. 6 years ago
David Wilson 219718740b Move django test script into permanent test 6 years ago
David Wilson ec1de4b4b9 tests: ensure strace is available in the docker image..
..and enable privileged=True since that's needed for ptrace()
6 years ago
David Wilson b2909ee5f4 Replace nasty print statements in six_brokenpkg. 6 years ago
Alex Willmer 7e01c5bed5 Import and use unittest2 without aliasing it 6 years ago
Alex Willmer e8e023ce59 Use specific TestCase assertions throughout tests
e.g. assert x == y -> self.assertEqual(x, y);
self.assertTrue(isinstance(x, y)) -> self.assertIsInstance(x, y)

These specific methods give more useful errors in the case of a test
failure.
6 years ago
Alex Willmer df9556d1d9 Replace custom assertContains() with unitest2 assertIn() 6 years ago
Alex Willmer 17da6e9998 Use unittest2 in all tests
This allows using features such as TestCase,assertIsInstance on Python
2.6 and earlier.
6 years ago
Alex Willmer 3831ac360f Replace all calls to file() with open()
Although these are synonyms in Python 2.x, when using MyPy to typecheck
code use of file() causes spurious errors.

This commit also serves as one small step to Python 3.x compatibility,
since 3.x removes the file() builtin.
6 years ago
R W H Bricheno df61f6ab4d Prevent MacOS exception on shutdown of closed socket. 6 years ago
R W H Bricheno 39f325af3e Fix getting the directory path on Mac OS X. 6 years ago
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.
6 years ago
David Wilson 65defaa354 tests: initial first_stage_test. 6 years ago
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)")
```
6 years ago
Alex Willmer 94992940dd ssh_test: Correct hostname in SShTest.test_stream_name()
I presume that `u1704` is a relic of a bygone container/host.
6 years ago
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
6 years ago
David Wilson f8a84616d7 tests: stop responder_test spamming the logs 6 years ago
David Wilson 7389272dc4 tests: stop fakessh spamming the logs 6 years ago
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.
6 years ago
David Wilson 17a05dc14f Try to be compatible with older Docker daemons; (hopefully) closes #46 6 years ago
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.
6 years ago
David Wilson 32d029ed75 Add test that hangs the main thread during shutdown. 6 years ago
David Wilson 3285fc2f75 Implement test_aborted_on_local_context_disconnect 6 years ago
David Wilson dfe68b33d6 Handle docker running on localhost. 6 years ago
David Wilson bee1a86aa1 Let utils_test run directly too. 6 years ago
David Wilson 690ee6dbe2 Fix select_test failure, remove crap old timing_test. 6 years ago
David Wilson 9c8ff7ecf6 Remove proxy_test (duplicates sudo_test) 6 years ago
David Wilson f22d05a7ad frameworkize nested_test. 6 years ago
David Wilson 15bf0f54e2 Beginnings of module_finder_test 6 years ago
David Wilson d17af194b5 Fix importer_test constructor signature. 6 years ago
David Wilson 2454dcc990 core: loosen assertion to allow fakessh_test to succeed. 6 years ago
David Wilson bc801bc2ed Allow call_function_test to succeed depite testlib import. 6 years ago
David Wilson 118fe01be5 Use enhanced assertRaises in call_function_test.py. 6 years ago
David Wilson 9b13a4cc61 Fix 2 call_function_test failures. 6 years ago
David Wilson 236d83418c Simple scan_code_imports test. 6 years ago
David Wilson af6812b458 Fix context naming for sudo and via=. 6 years ago
David Wilson 1449c972eb Allow running responder_test with unittest. 6 years ago
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.
6 years ago
David Wilson bcae62c682 issue #20: TestCase subclass with a nicer assertRaises 6 years ago
David Wilson f869e088f8 issue #20: tests and fixes for mitogen.master.Select(). 6 years ago
David Wilson ced6d8e404 Fix up importer_test. 6 years ago
David Wilson 40e2e6eb4c Add README.md to tests subdir. 6 years ago
David Wilson 2fed3613e9 Syntax error. 6 years ago
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.
6 years ago
David Wilson 1510b72a25 fakessh: Add integration test for inter-child rsync. 6 years ago
David Wilson f01e457d70 Allow running without py.test. 6 years ago
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.
6 years ago
David Wilson 1411790f56 master: make write_all() handle O_NONBLOCK and deadlines. 6 years ago
David Wilson db225638f0 core: Make iter_read() handle deadline (and non-blocking IO) properly 6 years ago
David Wilson 3c8c1f71a6 Update test. 6 years ago
David Wilson 5dff221842 fakessh: cleanup master test. 6 years ago
David Wilson c67119501b Keep allocate_id() in the enhanced router class. 6 years ago
David Wilson 4720eb1c55 core: add ALLOCATE_ID message for fakessh. 6 years ago
David Wilson 502266f115 Fix Channel constructor and add simple test; closes #32 6 years ago
David Wilson 3a0f03183c Simple working fakessh_test. 6 years ago
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.
6 years ago
David Wilson f04a503caa Add rsync and git to build_docker_image too. 6 years ago
David Wilson e2d3ac9b6a Fixup some more tests. 6 years ago
David Wilson 2736592c79 First handful of functional tests for SSH against Docker. 6 years ago
David Wilson 91ff12f8d8 Import Docker build script for integration tests 6 years ago
David Wilson b51e41edb5 Working DockerMixin for tests. 6 years ago
David Wilson 1f99dcb435 fix unbelievably dumb variable shadowing 6 years ago
David Wilson 25e4724bac A few more mitogen.slave/master changes 6 years ago
David Wilson bdf4fcfbce Tidy up test. 6 years ago
David Wilson be9e55fe8c pickle: support Context(), use same unpickler everywhere.
* Support passing Context() objects in function calls and return values.
  Now the fakessh demo from the documentation index would work
  correctly.

* Since slaves can communicate with each other now, they should also use
  the same approach to unpickling as the master already used. Collapse
  away all the unpickle extension crap and hard-wire just the 3 types
  that support unpickling.
6 years ago
David Wilson 92ae866271 Import random old test scripts into tests/ dir. 6 years ago
David Wilson 996d847731 Add some broken tests 6 years ago
David Wilson e75f1d8579 Add call_function_test, fix various exception bugs. 6 years ago
David Wilson e7ff6259a3 Initial commit. 6 years ago