66package resolvedspan_test
77
88import (
9- "context"
109 "iter"
1110 "testing"
1211
@@ -24,8 +23,6 @@ func TestAggregatorFrontier(t *testing.T) {
2423 defer leaktest .AfterTest (t )()
2524 defer log .Scope (t ).Close (t )
2625
27- ctx := context .Background ()
28-
2926 // Create a fresh frontier with no progress.
3027 statementTime := makeTS (10 )
3128 var initialHighwater hlc.Timestamp
@@ -38,32 +35,37 @@ func TestAggregatorFrontier(t *testing.T) {
3835 require .Equal (t , initialHighwater , f .Frontier ())
3936
4037 // Forward spans representing initial scan.
41- testBackfillSpan (t , ctx , f , "a" , "b" , statementTime , initialHighwater )
42- testBackfillSpan (t , ctx , f , "b" , "f" , statementTime , statementTime )
38+ testBackfillSpan (t , f , "a" , "b" , statementTime , initialHighwater )
39+ testBackfillSpan (t , f , "b" , "f" , statementTime , statementTime )
4340
4441 // Forward spans signalling a backfill is required.
4542 backfillTS := makeTS (20 )
46- testBoundarySpan (t , ctx , f , "a" , "b" , backfillTS .Prev (), jobspb .ResolvedSpan_BACKFILL , statementTime )
47- testBoundarySpan (t , ctx , f , "b" , "c" , backfillTS .Prev (), jobspb .ResolvedSpan_BACKFILL , statementTime )
48- testBoundarySpan (t , ctx , f , "c" , "d" , backfillTS .Prev (), jobspb .ResolvedSpan_BACKFILL , statementTime )
49- testBoundarySpan (t , ctx , f , "d" , "e" , backfillTS .Prev (), jobspb .ResolvedSpan_BACKFILL , statementTime )
50- testBoundarySpan (t , ctx , f , "e" , "f" , backfillTS .Prev (), jobspb .ResolvedSpan_BACKFILL , backfillTS .Prev ())
43+ testBoundarySpan (t , f , "a" , "b" , backfillTS .Prev (), jobspb .ResolvedSpan_BACKFILL , statementTime )
44+ testBoundarySpan (t , f , "b" , "c" , backfillTS .Prev (), jobspb .ResolvedSpan_BACKFILL , statementTime )
45+ testBoundarySpan (t , f , "c" , "d" , backfillTS .Prev (), jobspb .ResolvedSpan_BACKFILL , statementTime )
46+ testBoundarySpan (t , f , "d" , "e" , backfillTS .Prev (), jobspb .ResolvedSpan_BACKFILL , statementTime )
47+ testBoundarySpan (t , f , "e" , "f" , backfillTS .Prev (), jobspb .ResolvedSpan_BACKFILL , backfillTS .Prev ())
5148
52- // Confirm that attempting to signal an earlier boundary causes an assertion error.
49+ // Verify that attempting to signal an earlier boundary causes an assertion error.
5350 illegalBoundaryTS := makeTS (15 )
54- testIllegalBoundarySpan (t , ctx , f , "a" , "f" , illegalBoundaryTS , jobspb .ResolvedSpan_BACKFILL )
55- testIllegalBoundarySpan (t , ctx , f , "a" , "f" , illegalBoundaryTS , jobspb .ResolvedSpan_RESTART )
56- testIllegalBoundarySpan (t , ctx , f , "a" , "f" , illegalBoundaryTS , jobspb .ResolvedSpan_EXIT )
51+ testIllegalBoundarySpan (t , f , "a" , "f" , illegalBoundaryTS , jobspb .ResolvedSpan_BACKFILL )
52+ testIllegalBoundarySpan (t , f , "a" , "f" , illegalBoundaryTS , jobspb .ResolvedSpan_RESTART )
53+ testIllegalBoundarySpan (t , f , "a" , "f" , illegalBoundaryTS , jobspb .ResolvedSpan_EXIT )
54+
55+ // Verify that attempting to signal a boundary at the latest boundary time with a different
56+ // boundary type causes an assertion error.
57+ testIllegalBoundarySpan (t , f , "a" , "f" , backfillTS .Prev (), jobspb .ResolvedSpan_RESTART )
58+ testIllegalBoundarySpan (t , f , "a" , "f" , backfillTS .Prev (), jobspb .ResolvedSpan_EXIT )
5759
5860 // Forward spans representing actual backfill.
59- testBackfillSpan (t , ctx , f , "d" , "e" , backfillTS , backfillTS .Prev ())
60- testBackfillSpan (t , ctx , f , "e" , "f" , backfillTS , backfillTS .Prev ())
61- testBackfillSpan (t , ctx , f , "a" , "d" , backfillTS , backfillTS )
61+ testBackfillSpan (t , f , "d" , "e" , backfillTS , backfillTS .Prev ())
62+ testBackfillSpan (t , f , "e" , "f" , backfillTS , backfillTS .Prev ())
63+ testBackfillSpan (t , f , "a" , "d" , backfillTS , backfillTS )
6264
6365 // Forward spans signalling a restart is required.
6466 restartTS := makeTS (30 )
65- testBoundarySpan (t , ctx , f , "a" , "b" , restartTS .Prev (), jobspb .ResolvedSpan_RESTART , backfillTS )
66- testBoundarySpan (t , ctx , f , "b" , "f" , restartTS .Prev (), jobspb .ResolvedSpan_RESTART , restartTS .Prev ())
67+ testBoundarySpan (t , f , "a" , "b" , restartTS .Prev (), jobspb .ResolvedSpan_RESTART , backfillTS )
68+ testBoundarySpan (t , f , "b" , "f" , restartTS .Prev (), jobspb .ResolvedSpan_RESTART , restartTS .Prev ())
6769
6870 // Simulate restarting by creating a new frontier with the initial highwater
6971 // set to the previous frontier timestamp.
@@ -76,21 +78,19 @@ func TestAggregatorFrontier(t *testing.T) {
7678 require .NoError (t , err )
7779
7880 // Forward spans representing post-restart backfill.
79- testBackfillSpan (t , ctx , f , "a" , "b" , restartTS , initialHighwater )
80- testBackfillSpan (t , ctx , f , "e" , "f" , restartTS , initialHighwater )
81- testBackfillSpan (t , ctx , f , "b" , "e" , restartTS , restartTS )
81+ testBackfillSpan (t , f , "a" , "b" , restartTS , initialHighwater )
82+ testBackfillSpan (t , f , "e" , "f" , restartTS , initialHighwater )
83+ testBackfillSpan (t , f , "b" , "e" , restartTS , restartTS )
8284
8385 // Forward spans signalling an exit is required.
8486 exitTS := makeTS (40 )
85- testBoundarySpan (t , ctx , f , "a" , "f" , exitTS .Prev (), jobspb .ResolvedSpan_EXIT , exitTS .Prev ())
87+ testBoundarySpan (t , f , "a" , "f" , exitTS .Prev (), jobspb .ResolvedSpan_EXIT , exitTS .Prev ())
8688}
8789
8890func TestCoordinatorFrontier (t * testing.T ) {
8991 defer leaktest .AfterTest (t )()
9092 defer log .Scope (t ).Close (t )
9193
92- ctx := context .Background ()
93-
9494 // Create a fresh frontier with no progress.
9595 statementTime := makeTS (10 )
9696 var initialHighwater hlc.Timestamp
@@ -103,35 +103,40 @@ func TestCoordinatorFrontier(t *testing.T) {
103103 require .Equal (t , initialHighwater , f .Frontier ())
104104
105105 // Forward spans representing initial scan.
106- testBackfillSpan (t , ctx , f , "a" , "b" , statementTime , initialHighwater )
107- testBackfillSpan (t , ctx , f , "b" , "f" , statementTime , statementTime )
106+ testBackfillSpan (t , f , "a" , "b" , statementTime , initialHighwater )
107+ testBackfillSpan (t , f , "b" , "f" , statementTime , statementTime )
108108
109109 // Forward span signalling a backfill is required.
110110 backfillTS1 := makeTS (15 )
111- testBoundarySpan (t , ctx , f , "a" , "b" , backfillTS1 .Prev (), jobspb .ResolvedSpan_BACKFILL , statementTime )
111+ testBoundarySpan (t , f , "a" , "b" , backfillTS1 .Prev (), jobspb .ResolvedSpan_BACKFILL , statementTime )
112112
113113 // Forward span signalling another backfill is required (simulates multiple
114114 // aggregators progressing at different speeds).
115115 backfillTS2 := makeTS (20 )
116- testBackfillSpan (t , ctx , f , "a" , "b" , backfillTS1 , statementTime )
117- testBoundarySpan (t , ctx , f , "a" , "b" , backfillTS2 .Prev (), jobspb .ResolvedSpan_BACKFILL , statementTime )
116+ testBackfillSpan (t , f , "a" , "b" , backfillTS1 , statementTime )
117+ testBoundarySpan (t , f , "a" , "b" , backfillTS2 .Prev (), jobspb .ResolvedSpan_BACKFILL , statementTime )
118118
119119 // Verify that spans signalling backfills at earlier timestamp are allowed.
120- testBoundarySpan (t , ctx , f , "b" , "c" , backfillTS1 .Prev (), jobspb .ResolvedSpan_BACKFILL , statementTime )
120+ testBoundarySpan (t , f , "b" , "c" , backfillTS1 .Prev (), jobspb .ResolvedSpan_BACKFILL , statementTime )
121121
122122 // Verify that no other boundary spans at earlier timestamp are allowed.
123- testIllegalBoundarySpan (t , ctx , f , "a" , "f" , backfillTS1 .Prev (), jobspb .ResolvedSpan_RESTART )
124- testIllegalBoundarySpan (t , ctx , f , "a" , "f" , backfillTS1 .Prev (), jobspb .ResolvedSpan_EXIT )
123+ testIllegalBoundarySpan (t , f , "a" , "f" , backfillTS1 .Prev (), jobspb .ResolvedSpan_RESTART )
124+ testIllegalBoundarySpan (t , f , "a" , "f" , backfillTS1 .Prev (), jobspb .ResolvedSpan_EXIT )
125+
126+ // Verify that attempting to signal a boundary at the latest boundary time with a different
127+ // boundary type causes an assertion error.
128+ testIllegalBoundarySpan (t , f , "a" , "f" , backfillTS2 .Prev (), jobspb .ResolvedSpan_RESTART )
129+ testIllegalBoundarySpan (t , f , "a" , "f" , backfillTS2 .Prev (), jobspb .ResolvedSpan_EXIT )
125130
126131 // Forward spans completing first backfill and signalling and completing second backfill.
127- testBackfillSpan (t , ctx , f , "b" , "f" , backfillTS1 , backfillTS1 )
128- testBoundarySpan (t , ctx , f , "b" , "f" , backfillTS2 .Prev (), jobspb .ResolvedSpan_BACKFILL , backfillTS2 .Prev ())
129- testBackfillSpan (t , ctx , f , "a" , "f" , backfillTS2 , backfillTS2 )
132+ testBackfillSpan (t , f , "b" , "f" , backfillTS1 , backfillTS1 )
133+ testBoundarySpan (t , f , "b" , "f" , backfillTS2 .Prev (), jobspb .ResolvedSpan_BACKFILL , backfillTS2 .Prev ())
134+ testBackfillSpan (t , f , "a" , "f" , backfillTS2 , backfillTS2 )
130135
131136 // Forward spans signalling a restart is required.
132137 restartTS := makeTS (30 )
133- testBoundarySpan (t , ctx , f , "a" , "b" , restartTS .Prev (), jobspb .ResolvedSpan_RESTART , backfillTS2 )
134- testBoundarySpan (t , ctx , f , "b" , "f" , restartTS .Prev (), jobspb .ResolvedSpan_RESTART , restartTS .Prev ())
138+ testBoundarySpan (t , f , "a" , "b" , restartTS .Prev (), jobspb .ResolvedSpan_RESTART , backfillTS2 )
139+ testBoundarySpan (t , f , "b" , "f" , restartTS .Prev (), jobspb .ResolvedSpan_RESTART , restartTS .Prev ())
135140
136141 // Simulate restarting by creating a new frontier with the initial highwater
137142 // set to the previous frontier timestamp.
@@ -144,13 +149,13 @@ func TestCoordinatorFrontier(t *testing.T) {
144149 require .NoError (t , err )
145150
146151 // Forward spans representing post-restart backfill.
147- testBackfillSpan (t , ctx , f , "a" , "b" , restartTS , initialHighwater )
148- testBackfillSpan (t , ctx , f , "e" , "f" , restartTS , initialHighwater )
149- testBackfillSpan (t , ctx , f , "b" , "e" , restartTS , restartTS )
152+ testBackfillSpan (t , f , "a" , "b" , restartTS , initialHighwater )
153+ testBackfillSpan (t , f , "e" , "f" , restartTS , initialHighwater )
154+ testBackfillSpan (t , f , "b" , "e" , restartTS , restartTS )
150155
151156 // Forward spans signalling an exit is required.
152157 exitTS := makeTS (40 )
153- testBoundarySpan (t , ctx , f , "a" , "f" , exitTS .Prev (), jobspb .ResolvedSpan_EXIT , exitTS .Prev ())
158+ testBoundarySpan (t , f , "a" , "f" , exitTS .Prev (), jobspb .ResolvedSpan_EXIT , exitTS .Prev ())
154159}
155160
156161type frontier interface {
@@ -162,12 +167,7 @@ type frontier interface {
162167}
163168
164169func testBackfillSpan (
165- t * testing.T ,
166- ctx context.Context ,
167- f frontier ,
168- start , end string ,
169- ts hlc.Timestamp ,
170- frontierAfterSpan hlc.Timestamp ,
170+ t * testing.T , f frontier , start , end string , ts hlc.Timestamp , frontierAfterSpan hlc.Timestamp ,
171171) {
172172 backfillSpan := makeResolvedSpan (start , end , ts , jobspb .ResolvedSpan_NONE )
173173 require .True (t , f .InBackfill (backfillSpan ))
@@ -178,7 +178,6 @@ func testBackfillSpan(
178178
179179func testBoundarySpan (
180180 t * testing.T ,
181- ctx context.Context ,
182181 f frontier ,
183182 start , end string ,
184183 boundaryTS hlc.Timestamp ,
@@ -213,7 +212,6 @@ func testBoundarySpan(
213212
214213func testIllegalBoundarySpan (
215214 t * testing.T ,
216- ctx context.Context ,
217215 f frontier ,
218216 start , end string ,
219217 boundaryTS hlc.Timestamp ,
0 commit comments