| 99 | |
| 100 | |
| 101 | def test_backup_push_fetch(tmpdir, small_push_dir, monkeypatch, config, |
| 102 | noop_pg_backup_statements): |
| 103 | import wal_e.tar_partition |
| 104 | |
| 105 | # check that _fsync_files() is called with the right |
| 106 | # arguments. There's a separate unit test in test_tar_hacks.py |
| 107 | # that it actually fsyncs the right files. |
| 108 | fsynced_files = [] |
| 109 | monkeypatch.setattr(wal_e.tar_partition, '_fsync_files', |
| 110 | lambda filenames: fsynced_files.extend(filenames)) |
| 111 | |
| 112 | config.main('backup-push', str(small_push_dir)) |
| 113 | |
| 114 | fetch_dir = tmpdir.join('fetch-to').ensure(dir=True) |
| 115 | |
| 116 | # Spin around backup-fetch LATEST for a while to paper over race |
| 117 | # conditions whereby a backup may not be visible to backup-fetch |
| 118 | # immediately. |
| 119 | from boto import exception |
| 120 | start = datetime.datetime.now() |
| 121 | deadline = start + datetime.timedelta(seconds=15) |
| 122 | while True: |
| 123 | try: |
| 124 | config.main('backup-fetch', str(fetch_dir), 'LATEST') |
| 125 | except exception.S3ResponseError: |
| 126 | if datetime.datetime.now() > deadline: |
| 127 | raise |
| 128 | else: |
| 129 | continue |
| 130 | else: |
| 131 | break |
| 132 | |
| 133 | assert fetch_dir.join('arbitrary-file').read() == \ |
| 134 | small_push_dir.join('arbitrary-file').read() |
| 135 | |
| 136 | for filename in fetch_dir.listdir(): |
| 137 | if filename.check(link=0): |
| 138 | assert str(filename) in fsynced_files |
| 139 | elif filename.check(link=1): |
| 140 | assert str(filename) not in fsynced_files |
| 141 | |
| 142 | |
| 143 | def test_delete_everything(config, small_push_dir, noop_pg_backup_statements): |