Commit Graph

242 Commits (4bd992e35a14ddd0a74e24347dceb997170cec3c)

Author SHA1 Message Date
David Wilson e4b49997d6 issue #164: whups, delete checked in binaries. 7 years ago
David Wilson d068a36c1e issue #164: more dir layout contortions.
all.yml slurps in tests from each file/subdir in the CWD.
7 years ago
David Wilson 680dc1bf68 issue #164: basic connection loader tests. 7 years ago
David Wilson 20ecd0af02 issue #164: fix makefile 7 years ago
David Wilson 48a0938d04 issue #164: add action module to return active strategy. 7 years ago
David Wilson 0247561fc7 issue #164: rename lib/modules 7 years ago
David Wilson 6aeb4e9f05 issue #164: precisely emulate Ansible's stdio behaviour.
* Use identical logic to select when stdout/stderr are merged, so
  'stdout', 'stdout_lines', 'stderr', 'stderr_lines' contain the same
  output before/after the extension.

* When stdout/stderr are merged, synthesize carriage returns just like
  the TTY layer.

* Mimic the SSH connection multiplexing message on stderr. Not really
  for user code, but so compare_output_test.sh needs fewer fixups.
7 years ago
David Wilson c5ca2e87ea issue #164: stop tests on first failure 7 years ago
David Wilson 26cc0f2724 issue #164: fix remote_tmp handling on <2.5 7 years ago
David Wilson 3ebe600389 issue #164: convert "examples" into actual tests
- Add new Travis mode, "ansible_tests.sh" that runs
  integrations/all.yml. Slowly build this up over time to cover more of
  the existing junk.

- Add basic assertions on the output of the existing runner__* files.

- Wire up 2.4.3/2.5.0 jobs in Travis.
7 years ago
David Wilson ae75a0ca8c issue #164: rearrange playbooks a little more 7 years ago
David Wilson 563639961d issue #164: dir structure is gross, but at least tab completion works :> 7 years ago
David Wilson 49aa8834b0 issue #164: split "examples" out into regression/integration tests. 7 years ago
David Wilson 4805f3cf36 issue #164: slightly flatten docker image layers 7 years ago
David Wilson 8ca8b43df1 tests/bench: import "slightly more reliable time" script 7 years ago
David Wilson eb402c8bd4 tests/bench: import wrapper script used for blog charts 7 years ago
David Wilson de27fb3a28 issue #174: test all io_op() logic. 7 years ago
Alex Willmer dc60f05a40 tests: Switch to unit2 test runner, with coverage
This means test files are imported as modules, not run as scripts. THey
can still be run individually if so desired. Test coverage is measured,
and an html report generated in htmlcov/. Test cases are automativally
discovered, so they need not be listed twice. An overall
passed/failed/skipped summary is printed, rather than for each file.

Arguments passed to ./test are passed on to unit2. For instance

    ./test -v

will print each test name as it is run.
7 years ago
Alex Willmer 7b8fef5284 tests: Make the tests directory an importable package
Required for test discovery by e.g. unit2, pytest
7 years ago
Alex Willmer a22294dda9 call_function_test: Fix assumption that we run as a script 7 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.
7 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.
7 years ago
Alex Willmer 48623763d6 minimize_source: Implement reindentation 7 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.
7 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.
7 years ago
Alex Willmer 3bf61bb311 tests: Clarify which minimize_source samples are the reference 7 years ago
Alex Willmer 35ae4e4227 Issue #160: Add minimize_source testcases 7 years ago
David Wilson bbb0f1bbd8 issue #155: fix double-fork behaviour and test it this time. 7 years ago
David Wilson 4c433dbed1 parent_test: Add explanation. 7 years ago
David Wilson bde1778373 tests: merge tty_create_child() test into parent_test and fix hang 7 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.
7 years ago
David Wilson f726ef86de tests: first_stage_test regression due to 1ff27ada49 7 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!
7 years ago
David Wilson fe614aa966 core: cleanup handlers on broker crash; closes #112. 7 years ago
David Wilson 1ff27ada49 Add maximum message size checks. Closes #151. 7 years ago
David Wilson 80a97fbc9b core: Rename Sender.put() to Sender.send().
Been annoying me for months.
7 years ago
David Wilson 085b3d21bd core: fix call_function_test regression
Second time in 3 weeks. So stupid. This time write tests.
7 years ago
David Wilson 0f29baa077 core: support pickling senders, Receiver.to_sender()
CC @moreati, in case this impacts you
7 years ago
David Wilson 17aef51e6e tests: Import .local() latency test 7 years ago
David Wilson a8a31728a0 tests: Import Latch soak test 7 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.
7 years ago
David Wilson 761cd9eaf8 tests: import tty_create_child_test.py. 7 years ago
David Wilson 7b12f84366 core: support CallError(str) for service.py. 7 years ago
David Wilson fccca54068 tests: ensure OpenSSL is initialized prior to test. 7 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.
7 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.
7 years ago
David Wilson 4f93c6823a issue #155: skeletal fork_test. 7 years ago
David Wilson 2d7821b824 tests: test_stream_name: fix non-localhost Docker 7 years ago
David Wilson 23e279b617 tests: get import_test limping back to health. 7 years ago
David Wilson f4ba66e3ee issue #155: allocate child IDs in batches of 1000.
Avoids a roundtrip for every fork.
7 years ago
David Wilson 2132c311b2 tests: mark some tests as skipped 7 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.
7 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'
```
7 years ago
Alex Willmer 0f82f68fee parent: Precompute preamble sizes for first stage
SSH command size: 453 (no change)
Preamble size: 8941 (-5 bytes)
7 years ago
Alex Willmer b433645d11 tests: Fix import error 7 years ago
Alex Willmer c6f3bfd93a tests: Correct path to apply_mode_spec() 7 years ago
David Wilson 23f78ca5a2 README: move testing bits into tests directory. 7 years ago
David Wilson f5b5e4849e tests: import very basic latch_test 7 years ago
David Wilson f6d87faf37 tests: import ansible_helpers_test. 7 years ago
Alex Willmer 4b373c421b core: Standardise type of Importer.whitelist
This seemed a reasonable streamlining, but I'm happy to be overruled.
7 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
7 years ago
Alex Willmer 491355548d tests: Fix typo in ResolveRelPathTest 7 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.
7 years ago
Alex Willmer eee312a57e tests: Fix expected values FindRelatedTest for Django 1.11.4 7 years ago
Alex Willmer 4424bfbb7a tests: Add new FindRelatedImportsTest 7 years ago
Alex Willmer 9e43f5e6ba tests: Remove module under search from expected results
This matches a tweak made in 8765f761c9
7 years ago
Alex Willmer 0f9bfc1e21 tests: Rename FindRelatedImportsTest -> FindRelatedTest 7 years ago
David Wilson afc8697288 core: Ensure add_handler() callbacks really receive _DEAD on shutdown 7 years ago
David Wilson ccd9c62399 tests: stubs for future whitelist/blacklist tests. 7 years ago
Alex Willmer f4405c6bbc Split IterReadTest & WriteAllTest into test_parent
This matches their respective functions under test, which now reside in
mitogen.parent.
7 years ago
Alex Willmer 4fb1b928b7 Adjust unittest for master -> parent split
Tests should now match changes in
4d31300dd0
7 years ago
Alex Willmer 9ccff0f5d1 Fix TypeError while initiliazing ImporterMixin
Since f44356af32 mitogen.core.Importer()
takes a Router instance.
7 years ago
Alex Willmer fa0f390d4d FIx syntax error in FindRelatedImportsTest.test_django_db_models 7 years ago
David Wilson dd088908df select: clean up API. 7 years ago
David Wilson 219718740b Move django test script into permanent test 7 years ago
David Wilson ec1de4b4b9 tests: ensure strace is available in the docker image..
..and enable privileged=True since that's needed for ptrace()
7 years ago
David Wilson b2909ee5f4 Replace nasty print statements in six_brokenpkg. 7 years ago
Alex Willmer 7e01c5bed5 Import and use unittest2 without aliasing it 7 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.
7 years ago
Alex Willmer df9556d1d9 Replace custom assertContains() with unitest2 assertIn() 7 years ago
Alex Willmer 17da6e9998 Use unittest2 in all tests
This allows using features such as TestCase,assertIsInstance on Python
2.6 and earlier.
7 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.
7 years ago
R W H Bricheno df61f6ab4d Prevent MacOS exception on shutdown of closed socket. 7 years ago
R W H Bricheno 39f325af3e Fix getting the directory path on Mac OS X. 7 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.
7 years ago
David Wilson 65defaa354 tests: initial first_stage_test. 7 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)")
```
7 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.
7 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
7 years ago
David Wilson f8a84616d7 tests: stop responder_test spamming the logs 7 years ago
David Wilson 7389272dc4 tests: stop fakessh spamming the logs 7 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.
7 years ago
David Wilson 17a05dc14f Try to be compatible with older Docker daemons; (hopefully) closes #46 7 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.
7 years ago
David Wilson 32d029ed75 Add test that hangs the main thread during shutdown. 7 years ago
David Wilson 3285fc2f75 Implement test_aborted_on_local_context_disconnect 7 years ago
David Wilson dfe68b33d6 Handle docker running on localhost. 7 years ago
David Wilson bee1a86aa1 Let utils_test run directly too. 7 years ago
David Wilson 690ee6dbe2 Fix select_test failure, remove crap old timing_test. 7 years ago
David Wilson 9c8ff7ecf6 Remove proxy_test (duplicates sudo_test) 7 years ago
David Wilson f22d05a7ad frameworkize nested_test. 7 years ago
David Wilson 15bf0f54e2 Beginnings of module_finder_test 7 years ago
David Wilson d17af194b5 Fix importer_test constructor signature. 7 years ago
David Wilson 2454dcc990 core: loosen assertion to allow fakessh_test to succeed. 7 years ago
David Wilson bc801bc2ed Allow call_function_test to succeed depite testlib import. 7 years ago
David Wilson 118fe01be5 Use enhanced assertRaises in call_function_test.py. 7 years ago
David Wilson 9b13a4cc61 Fix 2 call_function_test failures. 7 years ago
David Wilson 236d83418c Simple scan_code_imports test. 7 years ago
David Wilson af6812b458 Fix context naming for sudo and via=. 7 years ago
David Wilson 1449c972eb Allow running responder_test with unittest. 7 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.
7 years ago
David Wilson bcae62c682 issue #20: TestCase subclass with a nicer assertRaises 7 years ago
David Wilson f869e088f8 issue #20: tests and fixes for mitogen.master.Select(). 7 years ago
David Wilson ced6d8e404 Fix up importer_test. 7 years ago
David Wilson 40e2e6eb4c Add README.md to tests subdir. 7 years ago
David Wilson 2fed3613e9 Syntax error. 7 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.
7 years ago
David Wilson 1510b72a25 fakessh: Add integration test for inter-child rsync. 7 years ago
David Wilson f01e457d70 Allow running without py.test. 7 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.
7 years ago
David Wilson 1411790f56 master: make write_all() handle O_NONBLOCK and deadlines. 7 years ago
David Wilson db225638f0 core: Make iter_read() handle deadline (and non-blocking IO) properly 7 years ago
David Wilson 3c8c1f71a6 Update test. 7 years ago
David Wilson 5dff221842 fakessh: cleanup master test. 7 years ago
David Wilson c67119501b Keep allocate_id() in the enhanced router class. 7 years ago
David Wilson 4720eb1c55 core: add ALLOCATE_ID message for fakessh. 7 years ago
David Wilson 502266f115 Fix Channel constructor and add simple test; closes #32 7 years ago
David Wilson 3a0f03183c Simple working fakessh_test. 7 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.
7 years ago
David Wilson f04a503caa Add rsync and git to build_docker_image too. 7 years ago
David Wilson e2d3ac9b6a Fixup some more tests. 7 years ago
David Wilson 2736592c79 First handful of functional tests for SSH against Docker. 7 years ago
David Wilson 91ff12f8d8 Import Docker build script for integration tests 7 years ago
David Wilson b51e41edb5 Working DockerMixin for tests. 7 years ago
David Wilson 1f99dcb435 fix unbelievably dumb variable shadowing 7 years ago
David Wilson 25e4724bac A few more mitogen.slave/master changes 7 years ago
David Wilson bdf4fcfbce Tidy up test. 7 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.
7 years ago
David Wilson 92ae866271 Import random old test scripts into tests/ dir. 7 years ago
David Wilson 996d847731 Add some broken tests 7 years ago
David Wilson e75f1d8579 Add call_function_test, fix various exception bugs. 7 years ago
David Wilson e7ff6259a3 Initial commit. 7 years ago