MCPcopy Create free account
hub / github.com/wal-e/wal-e / test_wal_push_parallel

Function test_wal_push_parallel

tests/test_blackbox.py:37–88  ·  view source on GitHub ↗
(pg_xlog, config, monkeypatch)

Source from the content-addressed store, hash-verified

35
36
37def 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
91def test_wal_fetch_non_existent(tmpdir, config):

Callers

nothing calls this directly

Calls 5

GatherActionsClass · 0.85
seg_nameFunction · 0.85
touchMethod · 0.80
segMethod · 0.80
mainMethod · 0.45

Tested by

no test coverage detected