func watchKey(kv kvdb.Kvdb, t *testing.T) { fmt.Println("\nwatchKey") watchData := watchData{ t: t, key: "tree/key1", otherKey: "tree/otherKey1", stop: "stop", iterations: 2, } kv.Delete(watchData.key) kv.Delete(watchData.otherKey) // First create a key. We should not get update for this create. _, err := kv.Create(watchData.otherKey, []byte("bar"), 0) // Let the create operation finish and then start the watch time.Sleep(time.Second) err = kv.WatchKey(watchData.otherKey, 0, &watchData, watchFn) if err != nil { fmt.Printf("Cannot test watchKey: %v\n", err) return } err = kv.WatchKey(watchData.key, 0, &watchData, watchFn) if err != nil { fmt.Printf("Cannot test watchKey: %v\n", err) return } go watchUpdate(kv, &watchData) for watchData.watchStopped == false { time.Sleep(time.Millisecond * 100) } // Stop the second watch atomic.SwapInt32(&watchData.whichKey, 0) watchData.action = kvdb.KVCreate _, err = kv.Create(watchData.otherKey, []byte(watchData.stop), 0) }