(pg_xlog, config, monkeypatch)
| 35 | |
| 36 | |
| 37 | def test_wal_push_parallel(pg_xlog, config, monkeypatch): |
| 38 | from wal_e.worker import upload |
| 39 | |
| 40 | old_info = upload.logger.info |
| 41 | |
| 42 | class GatherActions(object): |
| 43 | def __init__(self): |
| 44 | self.actions = set() |
| 45 | |
| 46 | def __call__(self, *args, **kwargs): |
| 47 | s = kwargs['structured'] |
| 48 | self.actions.add((s['action'], s['state'])) |
| 49 | return old_info(*args, **kwargs) |
| 50 | |
| 51 | ga = GatherActions() |
| 52 | monkeypatch.setattr(upload.logger, 'info', ga) |
| 53 | |
| 54 | def seg_name(*parts): |
| 55 | return ''.join(str(p).zfill(8) for p in parts) |
| 56 | |
| 57 | segments = [seg_name(1, 1, x) for x in range(1, 4)] |
| 58 | |
| 59 | for s in segments: |
| 60 | pg_xlog.touch(s, '.ready') |
| 61 | |
| 62 | # Prepare the second segment with *only* a ready file, to make |
| 63 | # sure parallel-push doesn't crash when pg_xlog's file is missing. |
| 64 | pg_xlog.seg(segments[1]).remove() |
| 65 | |
| 66 | # This push has enough parallelism that it should attempt all the |
| 67 | # wal segments staged. |
| 68 | config.main('wal-push', '-p8', 'pg_xlog/' + segments[0]) |
| 69 | |
| 70 | # Ensure all three action types, particularly the "skip" state, |
| 71 | # are encountered. |
| 72 | assert ga.actions == set([('push-wal', 'begin'), |
| 73 | ('push-wal', 'skip'), |
| 74 | ('push-wal', 'complete')]) |
| 75 | |
| 76 | # An explicit request to upload a segment that doesn't exist must |
| 77 | # yield a failure. |
| 78 | # |
| 79 | # NB: Normally one would use pytest.raises, but in this case, |
| 80 | # e.value was *sometimes* giving an integer value, and sometimes |
| 81 | # the SystemExit value, whereas the builtin try/except constructs |
| 82 | # appear reliable by comparison. |
| 83 | try: |
| 84 | config.main('wal-push', '-p8', 'pg_xlog/' + segments[1]) |
| 85 | except SystemExit as e: |
| 86 | assert e.code == 1 |
| 87 | else: |
| 88 | assert False |
| 89 | |
| 90 | |
| 91 | def test_wal_fetch_non_existent(tmpdir, config): |
nothing calls this directly
no test coverage detected