| 78 | } |
| 79 | |
| 80 | func TestRecursiveUpdate(t *testing.T) { |
| 81 | syn := newSync(t) |
| 82 | syn.etcdClient.Delete(context.Background(), "/", etcd.WithPrefix()) |
| 83 | mustUpdate := func(key, value string) { |
| 84 | if err := syn.Update(key, value); err != nil { |
| 85 | t.Fatalf("unexpected error %s", err.Error()) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | mustUpdate("/a/b/c/d/1", "test1") |
| 90 | mustUpdate("/a/b/c/d/2", "test2") |
| 91 | mustUpdate("/a/b/c/d/3", "test3") |
| 92 | mustUpdate("/a/b/e/d/1", "test4") |
| 93 | mustUpdate("/a/b/e/d/2", "test5") |
| 94 | mustUpdate("/a/b/e/d/3", "test6") |
| 95 | |
| 96 | node, err := syn.Fetch("/a") |
| 97 | if err != nil { |
| 98 | t.Fatalf("unexpected error %s", err.Error()) |
| 99 | } |
| 100 | |
| 101 | checkNode(node, "/a", "", 1, t) |
| 102 | ab := node.Children[0] |
| 103 | checkNode(ab, "/a/b", "", 2, t) |
| 104 | abc := ab.Children[0] |
| 105 | checkNode(abc, "/a/b/c", "", 1, t) |
| 106 | abcd := abc.Children[0] |
| 107 | checkNode(abcd, "/a/b/c/d", "", 3, t) |
| 108 | checkNode(abcd.Children[0], "/a/b/c/d/1", "test1", 0, t) |
| 109 | checkNode(abcd.Children[1], "/a/b/c/d/2", "test2", 0, t) |
| 110 | checkNode(abcd.Children[2], "/a/b/c/d/3", "test3", 0, t) |
| 111 | |
| 112 | abe := ab.Children[1] |
| 113 | checkNode(abe, "/a/b/e", "", 1, t) |
| 114 | abed := abe.Children[0] |
| 115 | checkNode(abed, "/a/b/e/d", "", 3, t) |
| 116 | checkNode(abed.Children[0], "/a/b/e/d/1", "test4", 0, t) |
| 117 | checkNode(abed.Children[1], "/a/b/e/d/2", "test5", 0, t) |
| 118 | checkNode(abed.Children[2], "/a/b/e/d/3", "test6", 0, t) |
| 119 | |
| 120 | node, err = syn.Fetch("/a/b/c") |
| 121 | if err != nil { |
| 122 | t.Fatalf("unexpected error %s", err.Error()) |
| 123 | } |
| 124 | checkNode(abc, "/a/b/c", "", 1, t) |
| 125 | } |
| 126 | |
| 127 | func TestLockUnblocking(t *testing.T) { |
| 128 | sync0 := newSync(t) |