|
25 | 25 | ) |
26 | 26 |
|
27 | 27 |
|
28 | | -def test_windows_cover_the_range_without_gaps_or_overlap(): |
| 28 | +def test_windows_do_not_share_a_boundary(): |
| 29 | + # Diver-HUB ranges are inclusive at both ends, so touching windows both |
| 30 | + # return the reading logged exactly on the boundary. That duplicate reaches |
| 31 | + # the loader in one batch and Postgres rejects the statement: "ON CONFLICT |
| 32 | + # DO UPDATE command cannot affect row a second time". |
29 | 33 | windows = list(iter_windows(0, 10 * DAY, span=3 * DAY)) |
30 | 34 | assert windows[0].start == 0 |
31 | 35 | assert windows[-1].end == 10 * DAY |
32 | 36 | for earlier, later in zip(windows, windows[1:]): |
33 | | - assert earlier.end == later.start |
| 37 | + assert later.start == earlier.end + 1 |
| 38 | + |
| 39 | + |
| 40 | +def test_windows_leave_no_second_uncovered(): |
| 41 | + # The gap is exactly one second and timestamps are second-resolution, so |
| 42 | + # nothing can fall between two windows. |
| 43 | + windows = list(iter_windows(0, 10 * DAY, span=3 * DAY)) |
| 44 | + for earlier, later in zip(windows, windows[1:]): |
| 45 | + assert later.start - earlier.end == 1 |
34 | 46 |
|
35 | 47 |
|
36 | 48 | def test_final_window_is_truncated_not_overshot(): |
37 | 49 | # Overshooting would ask the API for a future range, which is at best waste |
38 | 50 | # and at worst a 400. |
39 | 51 | windows = list(iter_windows(0, 10 * DAY, span=3 * DAY)) |
40 | 52 | assert windows[-1].end == 10 * DAY |
41 | | - assert windows[-1].span == DAY |
| 53 | + assert all(w.end <= 10 * DAY for w in windows) |
42 | 54 |
|
43 | 55 |
|
44 | 56 | def test_range_shorter_than_span_is_a_single_window(): |
|
0 commit comments