@@ -294,6 +294,39 @@ func TestWatchFutureRev(t *testing.T) {
294
294
}
295
295
}
296
296
297
+ func TestWatchRestore (t * testing.T ) {
298
+ b , tmpPath := backend .NewDefaultTmpBackend ()
299
+ s := newWatchableStore (b , & lease.FakeLessor {}, nil )
300
+ defer cleanup (s , b , tmpPath )
301
+
302
+ testKey := []byte ("foo" )
303
+ testValue := []byte ("bar" )
304
+ rev := s .Put (testKey , testValue , lease .NoLease )
305
+
306
+ newBackend , newPath := backend .NewDefaultTmpBackend ()
307
+ newStore := newWatchableStore (newBackend , & lease.FakeLessor {}, nil )
308
+ defer cleanup (newStore , newBackend , newPath )
309
+
310
+ w := newStore .NewWatchStream ()
311
+ w .Watch (testKey , nil , rev - 1 )
312
+
313
+ newStore .Restore (b )
314
+ select {
315
+ case resp := <- w .Chan ():
316
+ if resp .Revision != rev {
317
+ t .Fatalf ("rev = %d, want %d" , resp .Revision , rev )
318
+ }
319
+ if len (resp .Events ) != 1 {
320
+ t .Fatalf ("failed to get events from the response" )
321
+ }
322
+ if resp .Events [0 ].Kv .ModRevision != rev {
323
+ t .Fatalf ("kv.rev = %d, want %d" , resp .Events [0 ].Kv .ModRevision , rev )
324
+ }
325
+ case <- time .After (time .Second ):
326
+ t .Fatal ("failed to receive event in 1 second." )
327
+ }
328
+ }
329
+
297
330
// TestWatchBatchUnsynced tests batching on unsynced watchers
298
331
func TestWatchBatchUnsynced (t * testing.T ) {
299
332
b , tmpPath := backend .NewDefaultTmpBackend ()
0 commit comments