@@ -147,3 +147,51 @@ func TestSyncMonitor_HandlesBlockNumberIncreasing(t *testing.T) {
147
147
148
148
assert .Equal (t , initialBlockNumber + 5 , finalBlockNumber , "block number should have been incremented correctly" )
149
149
}
150
+
151
+ func TestSyncMonitor_ContinuesWhenNoRows (t * testing.T ) {
152
+ parentCtx , cancelParent := context .WithCancel (context .Background ())
153
+ defer cancelParent ()
154
+
155
+ dbpool , closeDB := testsetup .NewTestDBPool (parentCtx , t , database .Definition )
156
+ defer func () {
157
+ closeDB ()
158
+ cancelParent ()
159
+ }()
160
+
161
+ _ , err := dbpool .Exec (parentCtx , `
162
+ CREATE TABLE IF NOT EXISTS transaction_submitted_events_synced_until(
163
+ enforce_one_row bool PRIMARY KEY DEFAULT true,
164
+ block_hash bytea NOT NULL,
165
+ block_number bigint NOT NULL CHECK (block_number >= 0),
166
+ slot bigint NOT NULL CHECK (slot >= 0)
167
+ );
168
+ ` )
169
+ if err != nil {
170
+ t .Fatalf ("failed to create table: %v" , err )
171
+ }
172
+
173
+ monitor := & gnosis.SyncMonitor {
174
+ DBPool : dbpool ,
175
+ CheckInterval : 5 * time .Second ,
176
+ }
177
+
178
+ monitorCtx , cancelMonitor := context .WithCancel (parentCtx )
179
+ defer cancelMonitor ()
180
+
181
+ errCh := make (chan error , 1 )
182
+ go func () {
183
+ err := service .RunWithSighandler (monitorCtx , monitor )
184
+ if err != nil {
185
+ errCh <- err
186
+ }
187
+ }()
188
+
189
+ time .Sleep (15 * time .Second )
190
+ cancelMonitor ()
191
+
192
+ select {
193
+ case err := <- errCh :
194
+ t .Fatalf ("expected monitor to continue without error, but got: %v" , err )
195
+ case <- time .After (1 * time .Second ):
196
+ }
197
+ }
0 commit comments