store_test.go 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. // Copyright 2015 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package store
  15. import (
  16. "testing"
  17. "time"
  18. "github.com/coreos/etcd/Godeps/_workspace/src/github.com/jonboulle/clockwork"
  19. "github.com/coreos/etcd/Godeps/_workspace/src/github.com/stretchr/testify/assert"
  20. etcdErr "github.com/coreos/etcd/error"
  21. )
  22. func TestNewStoreWithNamespaces(t *testing.T) {
  23. s := newStore("/0", "/1")
  24. _, err := s.Get("/0", false, false)
  25. assert.Nil(t, err, "")
  26. _, err = s.Get("/1", false, false)
  27. assert.Nil(t, err, "")
  28. }
  29. // Ensure that the store can retrieve an existing value.
  30. func TestStoreGetValue(t *testing.T) {
  31. s := newStore()
  32. s.Create("/foo", false, "bar", false, Permanent)
  33. var eidx uint64 = 1
  34. e, err := s.Get("/foo", false, false)
  35. assert.Nil(t, err, "")
  36. assert.Equal(t, e.EtcdIndex, eidx, "")
  37. assert.Equal(t, e.Action, "get", "")
  38. assert.Equal(t, e.Node.Key, "/foo", "")
  39. assert.Equal(t, *e.Node.Value, "bar", "")
  40. }
  41. // Ensure that any TTL <= minExpireTime becomes Permanent
  42. func TestMinExpireTime(t *testing.T) {
  43. s := newStore()
  44. fc := clockwork.NewFakeClock()
  45. s.clock = fc
  46. // FakeClock starts at 0, so minExpireTime should be far in the future.. but just in case
  47. assert.True(t, minExpireTime.After(fc.Now()), "minExpireTime should be ahead of FakeClock!")
  48. s.Create("/foo", false, "Y", false, fc.Now().Add(3*time.Second))
  49. fc.Advance(5 * time.Second)
  50. // Ensure it hasn't expired
  51. s.DeleteExpiredKeys(fc.Now())
  52. var eidx uint64 = 1
  53. e, err := s.Get("/foo", true, false)
  54. assert.Nil(t, err, "")
  55. assert.Equal(t, e.EtcdIndex, eidx, "")
  56. assert.Equal(t, e.Action, "get", "")
  57. assert.Equal(t, e.Node.Key, "/foo", "")
  58. assert.Equal(t, e.Node.TTL, 0)
  59. }
  60. // Ensure that the store can recrusively retrieve a directory listing.
  61. // Note that hidden files should not be returned.
  62. func TestStoreGetDirectory(t *testing.T) {
  63. s := newStore()
  64. fc := newFakeClock()
  65. s.clock = fc
  66. s.Create("/foo", true, "", false, Permanent)
  67. s.Create("/foo/bar", false, "X", false, Permanent)
  68. s.Create("/foo/_hidden", false, "*", false, Permanent)
  69. s.Create("/foo/baz", true, "", false, Permanent)
  70. s.Create("/foo/baz/bat", false, "Y", false, Permanent)
  71. s.Create("/foo/baz/_hidden", false, "*", false, Permanent)
  72. s.Create("/foo/baz/ttl", false, "Y", false, fc.Now().Add(time.Second*3))
  73. var eidx uint64 = 7
  74. e, err := s.Get("/foo", true, false)
  75. assert.Nil(t, err, "")
  76. assert.Equal(t, e.EtcdIndex, eidx, "")
  77. assert.Equal(t, e.Action, "get", "")
  78. assert.Equal(t, e.Node.Key, "/foo", "")
  79. assert.Equal(t, len(e.Node.Nodes), 2, "")
  80. var bazNodes NodeExterns
  81. for _, node := range e.Node.Nodes {
  82. switch node.Key {
  83. case "/foo/bar":
  84. assert.Equal(t, *node.Value, "X", "")
  85. assert.Equal(t, node.Dir, false, "")
  86. case "/foo/baz":
  87. assert.Equal(t, node.Dir, true, "")
  88. assert.Equal(t, len(node.Nodes), 2, "")
  89. bazNodes = node.Nodes
  90. default:
  91. t.Errorf("key = %s, not matched", node.Key)
  92. }
  93. }
  94. for _, node := range bazNodes {
  95. switch node.Key {
  96. case "/foo/baz/bat":
  97. assert.Equal(t, *node.Value, "Y", "")
  98. assert.Equal(t, node.Dir, false, "")
  99. case "/foo/baz/ttl":
  100. assert.Equal(t, *node.Value, "Y", "")
  101. assert.Equal(t, node.Dir, false, "")
  102. assert.Equal(t, node.TTL, 3, "")
  103. default:
  104. t.Errorf("key = %s, not matched", node.Key)
  105. }
  106. }
  107. }
  108. // Ensure that the store can retrieve a directory in sorted order.
  109. func TestStoreGetSorted(t *testing.T) {
  110. s := newStore()
  111. s.Create("/foo", true, "", false, Permanent)
  112. s.Create("/foo/x", false, "0", false, Permanent)
  113. s.Create("/foo/z", false, "0", false, Permanent)
  114. s.Create("/foo/y", true, "", false, Permanent)
  115. s.Create("/foo/y/a", false, "0", false, Permanent)
  116. s.Create("/foo/y/b", false, "0", false, Permanent)
  117. var eidx uint64 = 6
  118. e, err := s.Get("/foo", true, true)
  119. assert.Nil(t, err, "")
  120. assert.Equal(t, e.EtcdIndex, eidx, "")
  121. var yNodes NodeExterns
  122. for _, node := range e.Node.Nodes {
  123. switch node.Key {
  124. case "/foo/x":
  125. case "/foo/y":
  126. yNodes = node.Nodes
  127. case "/foo/z":
  128. default:
  129. t.Errorf("key = %s, not matched", node.Key)
  130. }
  131. }
  132. for _, node := range yNodes {
  133. switch node.Key {
  134. case "/foo/y/a":
  135. case "/foo/y/b":
  136. default:
  137. t.Errorf("key = %s, not matched", node.Key)
  138. }
  139. }
  140. }
  141. func TestSet(t *testing.T) {
  142. s := newStore()
  143. // Set /foo=""
  144. var eidx uint64 = 1
  145. e, err := s.Set("/foo", false, "", Permanent)
  146. assert.Nil(t, err, "")
  147. assert.Equal(t, e.EtcdIndex, eidx, "")
  148. assert.Equal(t, e.Action, "set", "")
  149. assert.Equal(t, e.Node.Key, "/foo", "")
  150. assert.False(t, e.Node.Dir, "")
  151. assert.Equal(t, *e.Node.Value, "", "")
  152. assert.Nil(t, e.Node.Nodes, "")
  153. assert.Nil(t, e.Node.Expiration, "")
  154. assert.Equal(t, e.Node.TTL, 0, "")
  155. assert.Equal(t, e.Node.ModifiedIndex, uint64(1), "")
  156. // Set /foo="bar"
  157. eidx = 2
  158. e, err = s.Set("/foo", false, "bar", Permanent)
  159. assert.Nil(t, err, "")
  160. assert.Equal(t, e.EtcdIndex, eidx, "")
  161. assert.Equal(t, e.Action, "set", "")
  162. assert.Equal(t, e.Node.Key, "/foo", "")
  163. assert.False(t, e.Node.Dir, "")
  164. assert.Equal(t, *e.Node.Value, "bar", "")
  165. assert.Nil(t, e.Node.Nodes, "")
  166. assert.Nil(t, e.Node.Expiration, "")
  167. assert.Equal(t, e.Node.TTL, 0, "")
  168. assert.Equal(t, e.Node.ModifiedIndex, uint64(2), "")
  169. // check prevNode
  170. assert.NotNil(t, e.PrevNode, "")
  171. assert.Equal(t, e.PrevNode.Key, "/foo", "")
  172. assert.Equal(t, *e.PrevNode.Value, "", "")
  173. assert.Equal(t, e.PrevNode.ModifiedIndex, uint64(1), "")
  174. // Set /foo="baz" (for testing prevNode)
  175. eidx = 3
  176. e, err = s.Set("/foo", false, "baz", Permanent)
  177. assert.Nil(t, err, "")
  178. assert.Equal(t, e.EtcdIndex, eidx, "")
  179. assert.Equal(t, e.Action, "set", "")
  180. assert.Equal(t, e.Node.Key, "/foo", "")
  181. assert.False(t, e.Node.Dir, "")
  182. assert.Equal(t, *e.Node.Value, "baz", "")
  183. assert.Nil(t, e.Node.Nodes, "")
  184. assert.Nil(t, e.Node.Expiration, "")
  185. assert.Equal(t, e.Node.TTL, 0, "")
  186. assert.Equal(t, e.Node.ModifiedIndex, uint64(3), "")
  187. // check prevNode
  188. assert.NotNil(t, e.PrevNode, "")
  189. assert.Equal(t, e.PrevNode.Key, "/foo", "")
  190. assert.Equal(t, *e.PrevNode.Value, "bar", "")
  191. assert.Equal(t, e.PrevNode.ModifiedIndex, uint64(2), "")
  192. // Set /dir as a directory
  193. eidx = 4
  194. e, err = s.Set("/dir", true, "", Permanent)
  195. assert.Nil(t, err, "")
  196. assert.Equal(t, e.EtcdIndex, eidx, "")
  197. assert.Equal(t, e.Action, "set", "")
  198. assert.Equal(t, e.Node.Key, "/dir", "")
  199. assert.True(t, e.Node.Dir, "")
  200. assert.Nil(t, e.Node.Value)
  201. assert.Nil(t, e.Node.Nodes, "")
  202. assert.Nil(t, e.Node.Expiration, "")
  203. assert.Equal(t, e.Node.TTL, 0, "")
  204. assert.Equal(t, e.Node.ModifiedIndex, uint64(4), "")
  205. }
  206. // Ensure that the store can create a new key if it doesn't already exist.
  207. func TestStoreCreateValue(t *testing.T) {
  208. s := newStore()
  209. // Create /foo=bar
  210. var eidx uint64 = 1
  211. e, err := s.Create("/foo", false, "bar", false, Permanent)
  212. assert.Nil(t, err, "")
  213. assert.Equal(t, e.EtcdIndex, eidx, "")
  214. assert.Equal(t, e.Action, "create", "")
  215. assert.Equal(t, e.Node.Key, "/foo", "")
  216. assert.False(t, e.Node.Dir, "")
  217. assert.Equal(t, *e.Node.Value, "bar", "")
  218. assert.Nil(t, e.Node.Nodes, "")
  219. assert.Nil(t, e.Node.Expiration, "")
  220. assert.Equal(t, e.Node.TTL, 0, "")
  221. assert.Equal(t, e.Node.ModifiedIndex, uint64(1), "")
  222. // Create /empty=""
  223. eidx = 2
  224. e, err = s.Create("/empty", false, "", false, Permanent)
  225. assert.Nil(t, err, "")
  226. assert.Equal(t, e.EtcdIndex, eidx, "")
  227. assert.Equal(t, e.Action, "create", "")
  228. assert.Equal(t, e.Node.Key, "/empty", "")
  229. assert.False(t, e.Node.Dir, "")
  230. assert.Equal(t, *e.Node.Value, "", "")
  231. assert.Nil(t, e.Node.Nodes, "")
  232. assert.Nil(t, e.Node.Expiration, "")
  233. assert.Equal(t, e.Node.TTL, 0, "")
  234. assert.Equal(t, e.Node.ModifiedIndex, uint64(2), "")
  235. }
  236. // Ensure that the store can create a new directory if it doesn't already exist.
  237. func TestStoreCreateDirectory(t *testing.T) {
  238. s := newStore()
  239. var eidx uint64 = 1
  240. e, err := s.Create("/foo", true, "", false, Permanent)
  241. assert.Nil(t, err, "")
  242. assert.Equal(t, e.EtcdIndex, eidx, "")
  243. assert.Equal(t, e.Action, "create", "")
  244. assert.Equal(t, e.Node.Key, "/foo", "")
  245. assert.True(t, e.Node.Dir, "")
  246. }
  247. // Ensure that the store fails to create a key if it already exists.
  248. func TestStoreCreateFailsIfExists(t *testing.T) {
  249. s := newStore()
  250. // create /foo as dir
  251. s.Create("/foo", true, "", false, Permanent)
  252. // create /foo as dir again
  253. e, _err := s.Create("/foo", true, "", false, Permanent)
  254. err := _err.(*etcdErr.Error)
  255. assert.Equal(t, err.ErrorCode, etcdErr.EcodeNodeExist, "")
  256. assert.Equal(t, err.Message, "Key already exists", "")
  257. assert.Equal(t, err.Cause, "/foo", "")
  258. assert.Equal(t, err.Index, uint64(1), "")
  259. assert.Nil(t, e, 0, "")
  260. }
  261. // Ensure that the store can update a key if it already exists.
  262. func TestStoreUpdateValue(t *testing.T) {
  263. s := newStore()
  264. // create /foo=bar
  265. s.Create("/foo", false, "bar", false, Permanent)
  266. // update /foo="bzr"
  267. var eidx uint64 = 2
  268. e, err := s.Update("/foo", "baz", Permanent)
  269. assert.Nil(t, err, "")
  270. assert.Equal(t, e.EtcdIndex, eidx, "")
  271. assert.Equal(t, e.Action, "update", "")
  272. assert.Equal(t, e.Node.Key, "/foo", "")
  273. assert.False(t, e.Node.Dir, "")
  274. assert.Equal(t, *e.Node.Value, "baz", "")
  275. assert.Equal(t, e.Node.TTL, 0, "")
  276. assert.Equal(t, e.Node.ModifiedIndex, uint64(2), "")
  277. // check prevNode
  278. assert.Equal(t, e.PrevNode.Key, "/foo", "")
  279. assert.Equal(t, *e.PrevNode.Value, "bar", "")
  280. assert.Equal(t, e.PrevNode.TTL, 0, "")
  281. assert.Equal(t, e.PrevNode.ModifiedIndex, uint64(1), "")
  282. e, _ = s.Get("/foo", false, false)
  283. assert.Equal(t, *e.Node.Value, "baz", "")
  284. assert.Equal(t, e.EtcdIndex, eidx, "")
  285. // update /foo=""
  286. eidx = 3
  287. e, err = s.Update("/foo", "", Permanent)
  288. assert.Nil(t, err, "")
  289. assert.Equal(t, e.EtcdIndex, eidx, "")
  290. assert.Equal(t, e.Action, "update", "")
  291. assert.Equal(t, e.Node.Key, "/foo", "")
  292. assert.False(t, e.Node.Dir, "")
  293. assert.Equal(t, *e.Node.Value, "", "")
  294. assert.Equal(t, e.Node.TTL, 0, "")
  295. assert.Equal(t, e.Node.ModifiedIndex, uint64(3), "")
  296. // check prevNode
  297. assert.Equal(t, e.PrevNode.Key, "/foo", "")
  298. assert.Equal(t, *e.PrevNode.Value, "baz", "")
  299. assert.Equal(t, e.PrevNode.TTL, 0, "")
  300. assert.Equal(t, e.PrevNode.ModifiedIndex, uint64(2), "")
  301. e, _ = s.Get("/foo", false, false)
  302. assert.Equal(t, e.EtcdIndex, eidx, "")
  303. assert.Equal(t, *e.Node.Value, "", "")
  304. }
  305. // Ensure that the store cannot update a directory.
  306. func TestStoreUpdateFailsIfDirectory(t *testing.T) {
  307. s := newStore()
  308. s.Create("/foo", true, "", false, Permanent)
  309. e, _err := s.Update("/foo", "baz", Permanent)
  310. err := _err.(*etcdErr.Error)
  311. assert.Equal(t, err.ErrorCode, etcdErr.EcodeNotFile, "")
  312. assert.Equal(t, err.Message, "Not a file", "")
  313. assert.Equal(t, err.Cause, "/foo", "")
  314. assert.Nil(t, e, "")
  315. }
  316. // Ensure that the store can update the TTL on a value.
  317. func TestStoreUpdateValueTTL(t *testing.T) {
  318. s := newStore()
  319. fc := newFakeClock()
  320. s.clock = fc
  321. var eidx uint64 = 2
  322. s.Create("/foo", false, "bar", false, Permanent)
  323. _, err := s.Update("/foo", "baz", fc.Now().Add(500*time.Millisecond))
  324. e, _ := s.Get("/foo", false, false)
  325. assert.Equal(t, *e.Node.Value, "baz", "")
  326. assert.Equal(t, e.EtcdIndex, eidx, "")
  327. fc.Advance(600 * time.Millisecond)
  328. s.DeleteExpiredKeys(fc.Now())
  329. e, err = s.Get("/foo", false, false)
  330. assert.Nil(t, e, "")
  331. assert.Equal(t, err.(*etcdErr.Error).ErrorCode, etcdErr.EcodeKeyNotFound, "")
  332. }
  333. // Ensure that the store can update the TTL on a directory.
  334. func TestStoreUpdateDirTTL(t *testing.T) {
  335. s := newStore()
  336. fc := newFakeClock()
  337. s.clock = fc
  338. var eidx uint64 = 3
  339. s.Create("/foo", true, "", false, Permanent)
  340. s.Create("/foo/bar", false, "baz", false, Permanent)
  341. e, err := s.Update("/foo", "", fc.Now().Add(500*time.Millisecond))
  342. assert.Equal(t, e.Node.Dir, true, "")
  343. assert.Equal(t, e.EtcdIndex, eidx, "")
  344. e, _ = s.Get("/foo/bar", false, false)
  345. assert.Equal(t, *e.Node.Value, "baz", "")
  346. assert.Equal(t, e.EtcdIndex, eidx, "")
  347. fc.Advance(600 * time.Millisecond)
  348. s.DeleteExpiredKeys(fc.Now())
  349. e, err = s.Get("/foo/bar", false, false)
  350. assert.Nil(t, e, "")
  351. assert.Equal(t, err.(*etcdErr.Error).ErrorCode, etcdErr.EcodeKeyNotFound, "")
  352. }
  353. // Ensure that the store can delete a value.
  354. func TestStoreDeleteValue(t *testing.T) {
  355. s := newStore()
  356. var eidx uint64 = 2
  357. s.Create("/foo", false, "bar", false, Permanent)
  358. e, err := s.Delete("/foo", false, false)
  359. assert.Nil(t, err, "")
  360. assert.Equal(t, e.EtcdIndex, eidx, "")
  361. assert.Equal(t, e.Action, "delete", "")
  362. // check prevNode
  363. assert.NotNil(t, e.PrevNode, "")
  364. assert.Equal(t, e.PrevNode.Key, "/foo", "")
  365. assert.Equal(t, *e.PrevNode.Value, "bar", "")
  366. }
  367. // Ensure that the store can delete a directory if recursive is specified.
  368. func TestStoreDeleteDiretory(t *testing.T) {
  369. s := newStore()
  370. // create directory /foo
  371. var eidx uint64 = 2
  372. s.Create("/foo", true, "", false, Permanent)
  373. // delete /foo with dir = true and recursive = false
  374. // this should succeed, since the directory is empty
  375. e, err := s.Delete("/foo", true, false)
  376. assert.Nil(t, err, "")
  377. assert.Equal(t, e.EtcdIndex, eidx, "")
  378. assert.Equal(t, e.Action, "delete", "")
  379. // check prevNode
  380. assert.NotNil(t, e.PrevNode, "")
  381. assert.Equal(t, e.PrevNode.Key, "/foo", "")
  382. assert.Equal(t, e.PrevNode.Dir, true, "")
  383. // create directory /foo and directory /foo/bar
  384. s.Create("/foo/bar", true, "", false, Permanent)
  385. // delete /foo with dir = true and recursive = false
  386. // this should fail, since the directory is not empty
  387. _, err = s.Delete("/foo", true, false)
  388. assert.NotNil(t, err, "")
  389. // delete /foo with dir=false and recursive = true
  390. // this should succeed, since recursive implies dir=true
  391. // and recursively delete should be able to delete all
  392. // items under the given directory
  393. e, err = s.Delete("/foo", false, true)
  394. assert.Nil(t, err, "")
  395. assert.Equal(t, e.Action, "delete", "")
  396. }
  397. // Ensure that the store cannot delete a directory if both of recursive
  398. // and dir are not specified.
  399. func TestStoreDeleteDiretoryFailsIfNonRecursiveAndDir(t *testing.T) {
  400. s := newStore()
  401. s.Create("/foo", true, "", false, Permanent)
  402. e, _err := s.Delete("/foo", false, false)
  403. err := _err.(*etcdErr.Error)
  404. assert.Equal(t, err.ErrorCode, etcdErr.EcodeNotFile, "")
  405. assert.Equal(t, err.Message, "Not a file", "")
  406. assert.Nil(t, e, "")
  407. }
  408. func TestRootRdOnly(t *testing.T) {
  409. s := newStore("/0")
  410. for _, tt := range []string{"/", "/0"} {
  411. _, err := s.Set(tt, true, "", Permanent)
  412. assert.NotNil(t, err, "")
  413. _, err = s.Delete(tt, true, true)
  414. assert.NotNil(t, err, "")
  415. _, err = s.Create(tt, true, "", false, Permanent)
  416. assert.NotNil(t, err, "")
  417. _, err = s.Update(tt, "", Permanent)
  418. assert.NotNil(t, err, "")
  419. _, err = s.CompareAndSwap(tt, "", 0, "", Permanent)
  420. assert.NotNil(t, err, "")
  421. }
  422. }
  423. func TestStoreCompareAndDeletePrevValue(t *testing.T) {
  424. s := newStore()
  425. var eidx uint64 = 2
  426. s.Create("/foo", false, "bar", false, Permanent)
  427. e, err := s.CompareAndDelete("/foo", "bar", 0)
  428. assert.Nil(t, err, "")
  429. assert.Equal(t, e.EtcdIndex, eidx, "")
  430. assert.Equal(t, e.Action, "compareAndDelete", "")
  431. assert.Equal(t, e.Node.Key, "/foo", "")
  432. // check pervNode
  433. assert.NotNil(t, e.PrevNode, "")
  434. assert.Equal(t, e.PrevNode.Key, "/foo", "")
  435. assert.Equal(t, *e.PrevNode.Value, "bar", "")
  436. assert.Equal(t, e.PrevNode.ModifiedIndex, uint64(1), "")
  437. assert.Equal(t, e.PrevNode.CreatedIndex, uint64(1), "")
  438. }
  439. func TestStoreCompareAndDeletePrevValueFailsIfNotMatch(t *testing.T) {
  440. s := newStore()
  441. var eidx uint64 = 1
  442. s.Create("/foo", false, "bar", false, Permanent)
  443. e, _err := s.CompareAndDelete("/foo", "baz", 0)
  444. err := _err.(*etcdErr.Error)
  445. assert.Equal(t, err.ErrorCode, etcdErr.EcodeTestFailed, "")
  446. assert.Equal(t, err.Message, "Compare failed", "")
  447. assert.Nil(t, e, "")
  448. e, _ = s.Get("/foo", false, false)
  449. assert.Equal(t, e.EtcdIndex, eidx, "")
  450. assert.Equal(t, *e.Node.Value, "bar", "")
  451. }
  452. func TestStoreCompareAndDeletePrevIndex(t *testing.T) {
  453. s := newStore()
  454. var eidx uint64 = 2
  455. s.Create("/foo", false, "bar", false, Permanent)
  456. e, err := s.CompareAndDelete("/foo", "", 1)
  457. assert.Nil(t, err, "")
  458. assert.Equal(t, e.EtcdIndex, eidx, "")
  459. assert.Equal(t, e.Action, "compareAndDelete", "")
  460. // check pervNode
  461. assert.NotNil(t, e.PrevNode, "")
  462. assert.Equal(t, e.PrevNode.Key, "/foo", "")
  463. assert.Equal(t, *e.PrevNode.Value, "bar", "")
  464. assert.Equal(t, e.PrevNode.ModifiedIndex, uint64(1), "")
  465. assert.Equal(t, e.PrevNode.CreatedIndex, uint64(1), "")
  466. }
  467. func TestStoreCompareAndDeletePrevIndexFailsIfNotMatch(t *testing.T) {
  468. s := newStore()
  469. var eidx uint64 = 1
  470. s.Create("/foo", false, "bar", false, Permanent)
  471. e, _err := s.CompareAndDelete("/foo", "", 100)
  472. assert.NotNil(t, _err, "")
  473. err := _err.(*etcdErr.Error)
  474. assert.Equal(t, err.ErrorCode, etcdErr.EcodeTestFailed, "")
  475. assert.Equal(t, err.Message, "Compare failed", "")
  476. assert.Nil(t, e, "")
  477. e, _ = s.Get("/foo", false, false)
  478. assert.Equal(t, e.EtcdIndex, eidx, "")
  479. assert.Equal(t, *e.Node.Value, "bar", "")
  480. }
  481. // Ensure that the store cannot delete a directory.
  482. func TestStoreCompareAndDeleteDiretoryFail(t *testing.T) {
  483. s := newStore()
  484. s.Create("/foo", true, "", false, Permanent)
  485. _, _err := s.CompareAndDelete("/foo", "", 0)
  486. assert.NotNil(t, _err, "")
  487. err := _err.(*etcdErr.Error)
  488. assert.Equal(t, err.ErrorCode, etcdErr.EcodeNotFile, "")
  489. }
  490. // Ensure that the store can conditionally update a key if it has a previous value.
  491. func TestStoreCompareAndSwapPrevValue(t *testing.T) {
  492. s := newStore()
  493. var eidx uint64 = 2
  494. s.Create("/foo", false, "bar", false, Permanent)
  495. e, err := s.CompareAndSwap("/foo", "bar", 0, "baz", Permanent)
  496. assert.Nil(t, err, "")
  497. assert.Equal(t, e.EtcdIndex, eidx, "")
  498. assert.Equal(t, e.Action, "compareAndSwap", "")
  499. assert.Equal(t, *e.Node.Value, "baz", "")
  500. // check pervNode
  501. assert.NotNil(t, e.PrevNode, "")
  502. assert.Equal(t, e.PrevNode.Key, "/foo", "")
  503. assert.Equal(t, *e.PrevNode.Value, "bar", "")
  504. assert.Equal(t, e.PrevNode.ModifiedIndex, uint64(1), "")
  505. assert.Equal(t, e.PrevNode.CreatedIndex, uint64(1), "")
  506. e, _ = s.Get("/foo", false, false)
  507. assert.Equal(t, *e.Node.Value, "baz", "")
  508. }
  509. // Ensure that the store cannot conditionally update a key if it has the wrong previous value.
  510. func TestStoreCompareAndSwapPrevValueFailsIfNotMatch(t *testing.T) {
  511. s := newStore()
  512. var eidx uint64 = 1
  513. s.Create("/foo", false, "bar", false, Permanent)
  514. e, _err := s.CompareAndSwap("/foo", "wrong_value", 0, "baz", Permanent)
  515. err := _err.(*etcdErr.Error)
  516. assert.Equal(t, err.ErrorCode, etcdErr.EcodeTestFailed, "")
  517. assert.Equal(t, err.Message, "Compare failed", "")
  518. assert.Nil(t, e, "")
  519. e, _ = s.Get("/foo", false, false)
  520. assert.Equal(t, *e.Node.Value, "bar", "")
  521. assert.Equal(t, e.EtcdIndex, eidx, "")
  522. }
  523. // Ensure that the store can conditionally update a key if it has a previous index.
  524. func TestStoreCompareAndSwapPrevIndex(t *testing.T) {
  525. s := newStore()
  526. var eidx uint64 = 2
  527. s.Create("/foo", false, "bar", false, Permanent)
  528. e, err := s.CompareAndSwap("/foo", "", 1, "baz", Permanent)
  529. assert.Nil(t, err, "")
  530. assert.Equal(t, e.EtcdIndex, eidx, "")
  531. assert.Equal(t, e.Action, "compareAndSwap", "")
  532. assert.Equal(t, *e.Node.Value, "baz", "")
  533. // check prevNode
  534. assert.NotNil(t, e.PrevNode, "")
  535. assert.Equal(t, e.PrevNode.Key, "/foo", "")
  536. assert.Equal(t, *e.PrevNode.Value, "bar", "")
  537. assert.Equal(t, e.PrevNode.ModifiedIndex, uint64(1), "")
  538. assert.Equal(t, e.PrevNode.CreatedIndex, uint64(1), "")
  539. e, _ = s.Get("/foo", false, false)
  540. assert.Equal(t, *e.Node.Value, "baz", "")
  541. assert.Equal(t, e.EtcdIndex, eidx, "")
  542. }
  543. // Ensure that the store cannot conditionally update a key if it has the wrong previous index.
  544. func TestStoreCompareAndSwapPrevIndexFailsIfNotMatch(t *testing.T) {
  545. s := newStore()
  546. var eidx uint64 = 1
  547. s.Create("/foo", false, "bar", false, Permanent)
  548. e, _err := s.CompareAndSwap("/foo", "", 100, "baz", Permanent)
  549. err := _err.(*etcdErr.Error)
  550. assert.Equal(t, err.ErrorCode, etcdErr.EcodeTestFailed, "")
  551. assert.Equal(t, err.Message, "Compare failed", "")
  552. assert.Nil(t, e, "")
  553. e, _ = s.Get("/foo", false, false)
  554. assert.Equal(t, e.EtcdIndex, eidx, "")
  555. assert.Equal(t, *e.Node.Value, "bar", "")
  556. }
  557. // Ensure that the store can watch for key creation.
  558. func TestStoreWatchCreate(t *testing.T) {
  559. s := newStore()
  560. var eidx uint64 = 0
  561. w, _ := s.Watch("/foo", false, false, 0)
  562. c := w.EventChan()
  563. assert.Equal(t, w.StartIndex(), eidx, "")
  564. s.Create("/foo", false, "bar", false, Permanent)
  565. eidx = 1
  566. e := nbselect(c)
  567. assert.Equal(t, e.EtcdIndex, eidx, "")
  568. assert.Equal(t, e.Action, "create", "")
  569. assert.Equal(t, e.Node.Key, "/foo", "")
  570. e = nbselect(c)
  571. assert.Nil(t, e, "")
  572. }
  573. // Ensure that the store can watch for recursive key creation.
  574. func TestStoreWatchRecursiveCreate(t *testing.T) {
  575. s := newStore()
  576. var eidx uint64 = 0
  577. w, _ := s.Watch("/foo", true, false, 0)
  578. assert.Equal(t, w.StartIndex(), eidx, "")
  579. eidx = 1
  580. s.Create("/foo/bar", false, "baz", false, Permanent)
  581. e := nbselect(w.EventChan())
  582. assert.Equal(t, e.EtcdIndex, eidx, "")
  583. assert.Equal(t, e.Action, "create", "")
  584. assert.Equal(t, e.Node.Key, "/foo/bar", "")
  585. }
  586. // Ensure that the store can watch for key updates.
  587. func TestStoreWatchUpdate(t *testing.T) {
  588. s := newStore()
  589. var eidx uint64 = 1
  590. s.Create("/foo", false, "bar", false, Permanent)
  591. w, _ := s.Watch("/foo", false, false, 0)
  592. assert.Equal(t, w.StartIndex(), eidx, "")
  593. eidx = 2
  594. s.Update("/foo", "baz", Permanent)
  595. e := nbselect(w.EventChan())
  596. assert.Equal(t, e.EtcdIndex, eidx, "")
  597. assert.Equal(t, e.Action, "update", "")
  598. assert.Equal(t, e.Node.Key, "/foo", "")
  599. }
  600. // Ensure that the store can watch for recursive key updates.
  601. func TestStoreWatchRecursiveUpdate(t *testing.T) {
  602. s := newStore()
  603. var eidx uint64 = 1
  604. s.Create("/foo/bar", false, "baz", false, Permanent)
  605. w, _ := s.Watch("/foo", true, false, 0)
  606. assert.Equal(t, w.StartIndex(), eidx, "")
  607. eidx = 2
  608. s.Update("/foo/bar", "baz", Permanent)
  609. e := nbselect(w.EventChan())
  610. assert.Equal(t, e.EtcdIndex, eidx, "")
  611. assert.Equal(t, e.Action, "update", "")
  612. assert.Equal(t, e.Node.Key, "/foo/bar", "")
  613. }
  614. // Ensure that the store can watch for key deletions.
  615. func TestStoreWatchDelete(t *testing.T) {
  616. s := newStore()
  617. var eidx uint64 = 1
  618. s.Create("/foo", false, "bar", false, Permanent)
  619. w, _ := s.Watch("/foo", false, false, 0)
  620. assert.Equal(t, w.StartIndex(), eidx, "")
  621. eidx = 2
  622. s.Delete("/foo", false, false)
  623. e := nbselect(w.EventChan())
  624. assert.Equal(t, e.EtcdIndex, eidx, "")
  625. assert.Equal(t, e.Action, "delete", "")
  626. assert.Equal(t, e.Node.Key, "/foo", "")
  627. }
  628. // Ensure that the store can watch for recursive key deletions.
  629. func TestStoreWatchRecursiveDelete(t *testing.T) {
  630. s := newStore()
  631. var eidx uint64 = 1
  632. s.Create("/foo/bar", false, "baz", false, Permanent)
  633. w, _ := s.Watch("/foo", true, false, 0)
  634. assert.Equal(t, w.StartIndex(), eidx, "")
  635. eidx = 2
  636. s.Delete("/foo/bar", false, false)
  637. e := nbselect(w.EventChan())
  638. assert.Equal(t, e.EtcdIndex, eidx, "")
  639. assert.Equal(t, e.Action, "delete", "")
  640. assert.Equal(t, e.Node.Key, "/foo/bar", "")
  641. }
  642. // Ensure that the store can watch for CAS updates.
  643. func TestStoreWatchCompareAndSwap(t *testing.T) {
  644. s := newStore()
  645. var eidx uint64 = 1
  646. s.Create("/foo", false, "bar", false, Permanent)
  647. w, _ := s.Watch("/foo", false, false, 0)
  648. assert.Equal(t, w.StartIndex(), eidx, "")
  649. eidx = 2
  650. s.CompareAndSwap("/foo", "bar", 0, "baz", Permanent)
  651. e := nbselect(w.EventChan())
  652. assert.Equal(t, e.EtcdIndex, eidx, "")
  653. assert.Equal(t, e.Action, "compareAndSwap", "")
  654. assert.Equal(t, e.Node.Key, "/foo", "")
  655. }
  656. // Ensure that the store can watch for recursive CAS updates.
  657. func TestStoreWatchRecursiveCompareAndSwap(t *testing.T) {
  658. s := newStore()
  659. var eidx uint64 = 1
  660. s.Create("/foo/bar", false, "baz", false, Permanent)
  661. w, _ := s.Watch("/foo", true, false, 0)
  662. assert.Equal(t, w.StartIndex(), eidx, "")
  663. eidx = 2
  664. s.CompareAndSwap("/foo/bar", "baz", 0, "bat", Permanent)
  665. e := nbselect(w.EventChan())
  666. assert.Equal(t, e.EtcdIndex, eidx, "")
  667. assert.Equal(t, e.Action, "compareAndSwap", "")
  668. assert.Equal(t, e.Node.Key, "/foo/bar", "")
  669. }
  670. // Ensure that the store can watch for key expiration.
  671. func TestStoreWatchExpire(t *testing.T) {
  672. s := newStore()
  673. fc := newFakeClock()
  674. s.clock = fc
  675. var eidx uint64 = 2
  676. s.Create("/foo", false, "bar", false, fc.Now().Add(500*time.Millisecond))
  677. s.Create("/foofoo", false, "barbarbar", false, fc.Now().Add(500*time.Millisecond))
  678. w, _ := s.Watch("/", true, false, 0)
  679. assert.Equal(t, w.StartIndex(), eidx, "")
  680. c := w.EventChan()
  681. e := nbselect(c)
  682. assert.Nil(t, e, "")
  683. fc.Advance(600 * time.Millisecond)
  684. s.DeleteExpiredKeys(fc.Now())
  685. eidx = 3
  686. e = nbselect(c)
  687. assert.Equal(t, e.EtcdIndex, eidx, "")
  688. assert.Equal(t, e.Action, "expire", "")
  689. assert.Equal(t, e.Node.Key, "/foo", "")
  690. w, _ = s.Watch("/", true, false, 4)
  691. eidx = 4
  692. assert.Equal(t, w.StartIndex(), eidx, "")
  693. e = nbselect(w.EventChan())
  694. assert.Equal(t, e.EtcdIndex, eidx, "")
  695. assert.Equal(t, e.Action, "expire", "")
  696. assert.Equal(t, e.Node.Key, "/foofoo", "")
  697. }
  698. // Ensure that the store can watch in streaming mode.
  699. func TestStoreWatchStream(t *testing.T) {
  700. s := newStore()
  701. var eidx uint64 = 1
  702. w, _ := s.Watch("/foo", false, true, 0)
  703. // first modification
  704. s.Create("/foo", false, "bar", false, Permanent)
  705. e := nbselect(w.EventChan())
  706. assert.Equal(t, e.EtcdIndex, eidx, "")
  707. assert.Equal(t, e.Action, "create", "")
  708. assert.Equal(t, e.Node.Key, "/foo", "")
  709. assert.Equal(t, *e.Node.Value, "bar", "")
  710. e = nbselect(w.EventChan())
  711. assert.Nil(t, e, "")
  712. // second modification
  713. eidx = 2
  714. s.Update("/foo", "baz", Permanent)
  715. e = nbselect(w.EventChan())
  716. assert.Equal(t, e.EtcdIndex, eidx, "")
  717. assert.Equal(t, e.Action, "update", "")
  718. assert.Equal(t, e.Node.Key, "/foo", "")
  719. assert.Equal(t, *e.Node.Value, "baz", "")
  720. e = nbselect(w.EventChan())
  721. assert.Nil(t, e, "")
  722. }
  723. // Ensure that the store can recover from a previously saved state.
  724. func TestStoreRecover(t *testing.T) {
  725. s := newStore()
  726. var eidx uint64 = 4
  727. s.Create("/foo", true, "", false, Permanent)
  728. s.Create("/foo/x", false, "bar", false, Permanent)
  729. s.Update("/foo/x", "barbar", Permanent)
  730. s.Create("/foo/y", false, "baz", false, Permanent)
  731. b, err := s.Save()
  732. s2 := newStore()
  733. s2.Recovery(b)
  734. e, err := s.Get("/foo/x", false, false)
  735. assert.Equal(t, e.Node.CreatedIndex, uint64(2), "")
  736. assert.Equal(t, e.Node.ModifiedIndex, uint64(3), "")
  737. assert.Equal(t, e.EtcdIndex, eidx, "")
  738. assert.Nil(t, err, "")
  739. assert.Equal(t, *e.Node.Value, "barbar", "")
  740. e, err = s.Get("/foo/y", false, false)
  741. assert.Equal(t, e.EtcdIndex, eidx, "")
  742. assert.Nil(t, err, "")
  743. assert.Equal(t, *e.Node.Value, "baz", "")
  744. }
  745. // Ensure that the store can recover from a previously saved state that includes an expiring key.
  746. func TestStoreRecoverWithExpiration(t *testing.T) {
  747. s := newStore()
  748. s.clock = newFakeClock()
  749. fc := newFakeClock()
  750. var eidx uint64 = 4
  751. s.Create("/foo", true, "", false, Permanent)
  752. s.Create("/foo/x", false, "bar", false, Permanent)
  753. s.Create("/foo/y", false, "baz", false, fc.Now().Add(5*time.Millisecond))
  754. b, err := s.Save()
  755. time.Sleep(10 * time.Millisecond)
  756. s2 := newStore()
  757. s2.clock = fc
  758. s2.Recovery(b)
  759. fc.Advance(600 * time.Millisecond)
  760. s.DeleteExpiredKeys(fc.Now())
  761. e, err := s.Get("/foo/x", false, false)
  762. assert.Nil(t, err, "")
  763. assert.Equal(t, e.EtcdIndex, eidx, "")
  764. assert.Equal(t, *e.Node.Value, "bar", "")
  765. e, err = s.Get("/foo/y", false, false)
  766. assert.NotNil(t, err, "")
  767. assert.Nil(t, e, "")
  768. }
  769. // Ensure that the store can watch for hidden keys as long as it's an exact path match.
  770. func TestStoreWatchCreateWithHiddenKey(t *testing.T) {
  771. s := newStore()
  772. var eidx uint64 = 1
  773. w, _ := s.Watch("/_foo", false, false, 0)
  774. s.Create("/_foo", false, "bar", false, Permanent)
  775. e := nbselect(w.EventChan())
  776. assert.Equal(t, e.EtcdIndex, eidx, "")
  777. assert.Equal(t, e.Action, "create", "")
  778. assert.Equal(t, e.Node.Key, "/_foo", "")
  779. e = nbselect(w.EventChan())
  780. assert.Nil(t, e, "")
  781. }
  782. // Ensure that the store doesn't see hidden key creates without an exact path match in recursive mode.
  783. func TestStoreWatchRecursiveCreateWithHiddenKey(t *testing.T) {
  784. s := newStore()
  785. w, _ := s.Watch("/foo", true, false, 0)
  786. s.Create("/foo/_bar", false, "baz", false, Permanent)
  787. e := nbselect(w.EventChan())
  788. assert.Nil(t, e, "")
  789. w, _ = s.Watch("/foo", true, false, 0)
  790. s.Create("/foo/_baz", true, "", false, Permanent)
  791. e = nbselect(w.EventChan())
  792. assert.Nil(t, e, "")
  793. s.Create("/foo/_baz/quux", false, "quux", false, Permanent)
  794. e = nbselect(w.EventChan())
  795. assert.Nil(t, e, "")
  796. }
  797. // Ensure that the store doesn't see hidden key updates.
  798. func TestStoreWatchUpdateWithHiddenKey(t *testing.T) {
  799. s := newStore()
  800. s.Create("/_foo", false, "bar", false, Permanent)
  801. w, _ := s.Watch("/_foo", false, false, 0)
  802. s.Update("/_foo", "baz", Permanent)
  803. e := nbselect(w.EventChan())
  804. assert.Equal(t, e.Action, "update", "")
  805. assert.Equal(t, e.Node.Key, "/_foo", "")
  806. e = nbselect(w.EventChan())
  807. assert.Nil(t, e, "")
  808. }
  809. // Ensure that the store doesn't see hidden key updates without an exact path match in recursive mode.
  810. func TestStoreWatchRecursiveUpdateWithHiddenKey(t *testing.T) {
  811. s := newStore()
  812. s.Create("/foo/_bar", false, "baz", false, Permanent)
  813. w, _ := s.Watch("/foo", true, false, 0)
  814. s.Update("/foo/_bar", "baz", Permanent)
  815. e := nbselect(w.EventChan())
  816. assert.Nil(t, e, "")
  817. }
  818. // Ensure that the store can watch for key deletions.
  819. func TestStoreWatchDeleteWithHiddenKey(t *testing.T) {
  820. s := newStore()
  821. var eidx uint64 = 2
  822. s.Create("/_foo", false, "bar", false, Permanent)
  823. w, _ := s.Watch("/_foo", false, false, 0)
  824. s.Delete("/_foo", false, false)
  825. e := nbselect(w.EventChan())
  826. assert.Equal(t, e.EtcdIndex, eidx, "")
  827. assert.Equal(t, e.Action, "delete", "")
  828. assert.Equal(t, e.Node.Key, "/_foo", "")
  829. e = nbselect(w.EventChan())
  830. assert.Nil(t, e, "")
  831. }
  832. // Ensure that the store doesn't see hidden key deletes without an exact path match in recursive mode.
  833. func TestStoreWatchRecursiveDeleteWithHiddenKey(t *testing.T) {
  834. s := newStore()
  835. s.Create("/foo/_bar", false, "baz", false, Permanent)
  836. w, _ := s.Watch("/foo", true, false, 0)
  837. s.Delete("/foo/_bar", false, false)
  838. e := nbselect(w.EventChan())
  839. assert.Nil(t, e, "")
  840. }
  841. // Ensure that the store doesn't see expirations of hidden keys.
  842. func TestStoreWatchExpireWithHiddenKey(t *testing.T) {
  843. s := newStore()
  844. fc := newFakeClock()
  845. s.clock = fc
  846. s.Create("/_foo", false, "bar", false, fc.Now().Add(500*time.Millisecond))
  847. s.Create("/foofoo", false, "barbarbar", false, fc.Now().Add(1000*time.Millisecond))
  848. w, _ := s.Watch("/", true, false, 0)
  849. c := w.EventChan()
  850. e := nbselect(c)
  851. assert.Nil(t, e, "")
  852. fc.Advance(600 * time.Millisecond)
  853. s.DeleteExpiredKeys(fc.Now())
  854. e = nbselect(c)
  855. assert.Nil(t, e, "")
  856. fc.Advance(600 * time.Millisecond)
  857. s.DeleteExpiredKeys(fc.Now())
  858. e = nbselect(c)
  859. assert.Equal(t, e.Action, "expire", "")
  860. assert.Equal(t, e.Node.Key, "/foofoo", "")
  861. }
  862. // Ensure that the store does see hidden key creates if watching deeper than a hidden key in recursive mode.
  863. func TestStoreWatchRecursiveCreateDeeperThanHiddenKey(t *testing.T) {
  864. s := newStore()
  865. var eidx uint64 = 1
  866. w, _ := s.Watch("/_foo/bar", true, false, 0)
  867. s.Create("/_foo/bar/baz", false, "baz", false, Permanent)
  868. e := nbselect(w.EventChan())
  869. assert.NotNil(t, e, "")
  870. assert.Equal(t, e.EtcdIndex, eidx, "")
  871. assert.Equal(t, e.Action, "create", "")
  872. assert.Equal(t, e.Node.Key, "/_foo/bar/baz", "")
  873. }
  874. // Ensure that slow consumers are handled properly.
  875. //
  876. // Since Watcher.EventChan() has a buffer of size 1 we can only queue 1
  877. // event per watcher. If the consumer cannot consume the event on time and
  878. // another event arrives, the channel is closed and event is discarded.
  879. // This test ensures that after closing the channel, the store can continue
  880. // to operate correctly.
  881. func TestStoreWatchSlowConsumer(t *testing.T) {
  882. s := newStore()
  883. s.Watch("/foo", true, true, 0) // stream must be true
  884. s.Set("/foo", false, "1", Permanent) // ok
  885. s.Set("/foo", false, "2", Permanent) // ok
  886. s.Set("/foo", false, "3", Permanent) // must not panic
  887. }
  888. // Performs a non-blocking select on an event channel.
  889. func nbselect(c <-chan *Event) *Event {
  890. select {
  891. case e := <-c:
  892. return e
  893. default:
  894. return nil
  895. }
  896. }
  897. // newFakeClock creates a new FakeClock that has been advanced to at least minExpireTime
  898. func newFakeClock() clockwork.FakeClock {
  899. fc := clockwork.NewFakeClock()
  900. for minExpireTime.After(fc.Now()) {
  901. fc.Advance((0x1 << 62) * time.Nanosecond)
  902. }
  903. return fc
  904. }