tracking.tcl 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. start_server {tags {"tracking network"}} {
  2. # Create a deferred client we'll use to redirect invalidation
  3. # messages to.
  4. set rd_redirection [redis_deferring_client]
  5. $rd_redirection client id
  6. set redir_id [$rd_redirection read]
  7. $rd_redirection subscribe __redis__:invalidate
  8. $rd_redirection read ; # Consume the SUBSCRIBE reply.
  9. # Create another client that's not used as a redirection client
  10. # We should always keep this client's buffer clean
  11. set rd [redis_deferring_client]
  12. # Client to be used for SET and GET commands
  13. # We don't read this client's buffer
  14. set rd_sg [redis_client]
  15. proc clean_all {} {
  16. uplevel {
  17. # We should make r TRACKING off first. If r is in RESP3,
  18. # r FLUSH ALL will send us tracking-redir-broken or other
  19. # info which will not be consumed.
  20. r CLIENT TRACKING off
  21. $rd QUIT
  22. $rd_redirection QUIT
  23. set rd [redis_deferring_client]
  24. set rd_redirection [redis_deferring_client]
  25. $rd_redirection client id
  26. set redir_id [$rd_redirection read]
  27. $rd_redirection subscribe __redis__:invalidate
  28. $rd_redirection read ; # Consume the SUBSCRIBE reply.
  29. r FLUSHALL
  30. r HELLO 2
  31. r config set tracking-table-max-keys 1000000
  32. }
  33. }
  34. test {Clients are able to enable tracking and redirect it} {
  35. r CLIENT TRACKING on REDIRECT $redir_id
  36. } {*OK}
  37. test {The other connection is able to get invalidations} {
  38. r SET a{t} 1
  39. r SET b{t} 1
  40. r GET a{t}
  41. r INCR b{t} ; # This key should not be notified, since it wasn't fetched.
  42. r INCR a{t}
  43. set keys [lindex [$rd_redirection read] 2]
  44. assert {[llength $keys] == 1}
  45. assert {[lindex $keys 0] eq {a{t}}}
  46. }
  47. test {The client is now able to disable tracking} {
  48. # Make sure to add a few more keys in the tracking list
  49. # so that we can check for leaks, as a side effect.
  50. r MGET a{t} b{t} c{t} d{t} e{t} f{t} g{t}
  51. r CLIENT TRACKING off
  52. } {*OK}
  53. test {Clients can enable the BCAST mode with the empty prefix} {
  54. r CLIENT TRACKING on BCAST REDIRECT $redir_id
  55. } {*OK*}
  56. test {The connection gets invalidation messages about all the keys} {
  57. r MSET a{t} 1 b{t} 2 c{t} 3
  58. set keys [lsort [lindex [$rd_redirection read] 2]]
  59. assert {$keys eq {a{t} b{t} c{t}}}
  60. }
  61. test {Clients can enable the BCAST mode with prefixes} {
  62. r CLIENT TRACKING off
  63. r CLIENT TRACKING on BCAST REDIRECT $redir_id PREFIX a: PREFIX b:
  64. r MULTI
  65. r INCR a:1{t}
  66. r INCR a:2{t}
  67. r INCR b:1{t}
  68. r INCR b:2{t}
  69. # we should not get this key
  70. r INCR c:1{t}
  71. r EXEC
  72. # Because of the internals, we know we are going to receive
  73. # two separated notifications for the two different prefixes.
  74. set keys1 [lsort [lindex [$rd_redirection read] 2]]
  75. set keys2 [lsort [lindex [$rd_redirection read] 2]]
  76. set keys [lsort [list {*}$keys1 {*}$keys2]]
  77. assert {$keys eq {a:1{t} a:2{t} b:1{t} b:2{t}}}
  78. }
  79. test {Adding prefixes to BCAST mode works} {
  80. r CLIENT TRACKING on BCAST REDIRECT $redir_id PREFIX c:
  81. r INCR c:1234
  82. set keys [lsort [lindex [$rd_redirection read] 2]]
  83. assert {$keys eq {c:1234}}
  84. }
  85. test {Tracking NOLOOP mode in standard mode works} {
  86. r CLIENT TRACKING off
  87. r CLIENT TRACKING on REDIRECT $redir_id NOLOOP
  88. r MGET otherkey1{t} loopkey{t} otherkey2{t}
  89. $rd_sg SET otherkey1{t} 1; # We should get this
  90. r SET loopkey{t} 1 ; # We should not get this
  91. $rd_sg SET otherkey2{t} 1; # We should get this
  92. # Because of the internals, we know we are going to receive
  93. # two separated notifications for the two different keys.
  94. set keys1 [lsort [lindex [$rd_redirection read] 2]]
  95. set keys2 [lsort [lindex [$rd_redirection read] 2]]
  96. set keys [lsort [list {*}$keys1 {*}$keys2]]
  97. assert {$keys eq {otherkey1{t} otherkey2{t}}}
  98. }
  99. test {Tracking NOLOOP mode in BCAST mode works} {
  100. r CLIENT TRACKING off
  101. r CLIENT TRACKING on BCAST REDIRECT $redir_id NOLOOP
  102. $rd_sg SET otherkey1 1; # We should get this
  103. r SET loopkey 1 ; # We should not get this
  104. $rd_sg SET otherkey2 1; # We should get this
  105. # Because $rd_sg send command synchronously, we know we are
  106. # going to receive two separated notifications.
  107. set keys1 [lsort [lindex [$rd_redirection read] 2]]
  108. set keys2 [lsort [lindex [$rd_redirection read] 2]]
  109. set keys [lsort [list {*}$keys1 {*}$keys2]]
  110. assert {$keys eq {otherkey1 otherkey2}}
  111. }
  112. test {Tracking gets notification of expired keys} {
  113. r CLIENT TRACKING off
  114. r CLIENT TRACKING on BCAST REDIRECT $redir_id NOLOOP
  115. r SET mykey myval px 1
  116. r SET mykeyotherkey myval ; # We should not get it
  117. after 1000
  118. set keys [lsort [lindex [$rd_redirection read] 2]]
  119. assert {$keys eq {mykey}}
  120. }
  121. test {Tracking gets notification of lazy expired keys} {
  122. r CLIENT TRACKING off
  123. r CLIENT TRACKING on BCAST REDIRECT $redir_id NOLOOP
  124. # Use multi-exec to expose a race where the key gets an two invalidations
  125. # in the same event loop, once by the client so filtered by NOLOOP, and
  126. # the second one by the lazy expire
  127. r MULTI
  128. r SET mykey{t} myval px 1
  129. r SET mykeyotherkey{t} myval ; # We should not get it
  130. r DEBUG SLEEP 0.1
  131. r GET mykey{t}
  132. r EXEC
  133. set keys [lsort [lindex [$rd_redirection read] 2]]
  134. assert {$keys eq {mykey{t}}}
  135. } {} {needs:debug}
  136. test {HELLO 3 reply is correct} {
  137. set reply [r HELLO 3]
  138. assert_equal [dict get $reply proto] 3
  139. }
  140. test {HELLO without protover} {
  141. set reply [r HELLO 3]
  142. assert_equal [dict get $reply proto] 3
  143. set reply [r HELLO]
  144. assert_equal [dict get $reply proto] 3
  145. set reply [r HELLO 2]
  146. assert_equal [dict get $reply proto] 2
  147. set reply [r HELLO]
  148. assert_equal [dict get $reply proto] 2
  149. # restore RESP3 for next test
  150. r HELLO 3
  151. }
  152. test {RESP3 based basic invalidation} {
  153. r CLIENT TRACKING off
  154. r CLIENT TRACKING on
  155. $rd_sg SET key1 1
  156. r GET key1
  157. $rd_sg SET key1 2
  158. r read
  159. } {invalidate key1}
  160. test {RESP3 tracking redirection} {
  161. r CLIENT TRACKING off
  162. r CLIENT TRACKING on REDIRECT $redir_id
  163. $rd_sg SET key1 1
  164. r GET key1
  165. $rd_sg SET key1 2
  166. set res [lindex [$rd_redirection read] 2]
  167. assert {$res eq {key1}}
  168. }
  169. test {Invalidations of previous keys can be redirected after switching to RESP3} {
  170. r HELLO 2
  171. $rd_sg SET key1 1
  172. r GET key1
  173. r HELLO 3
  174. $rd_sg SET key1 2
  175. set res [lindex [$rd_redirection read] 2]
  176. assert {$res eq {key1}}
  177. }
  178. test {Invalidations of new keys can be redirected after switching to RESP3} {
  179. r HELLO 3
  180. $rd_sg SET key1 1
  181. r GET key1
  182. $rd_sg SET key1 2
  183. set res [lindex [$rd_redirection read] 2]
  184. assert {$res eq {key1}}
  185. }
  186. test {RESP3 Client gets tracking-redir-broken push message after cached key changed when rediretion client is terminated} {
  187. r CLIENT TRACKING on REDIRECT $redir_id
  188. $rd_sg SET key1 1
  189. r GET key1
  190. $rd_redirection QUIT
  191. assert_equal OK [$rd_redirection read]
  192. $rd_sg SET key1 2
  193. set MAX_TRIES 100
  194. set res -1
  195. for {set i 0} {$i <= $MAX_TRIES && $res < 0} {incr i} {
  196. set res [lsearch -exact [r PING] "tracking-redir-broken"]
  197. }
  198. assert {$res >= 0}
  199. # Consume PING reply
  200. assert_equal PONG [r read]
  201. # Reinstantiating after QUIT
  202. set rd_redirection [redis_deferring_client]
  203. $rd_redirection CLIENT ID
  204. set redir_id [$rd_redirection read]
  205. $rd_redirection SUBSCRIBE __redis__:invalidate
  206. $rd_redirection read ; # Consume the SUBSCRIBE reply
  207. }
  208. test {Different clients can redirect to the same connection} {
  209. r CLIENT TRACKING on REDIRECT $redir_id
  210. $rd CLIENT TRACKING on REDIRECT $redir_id
  211. assert_equal OK [$rd read] ; # Consume the TRACKING reply
  212. $rd_sg MSET key1{t} 1 key2{t} 1
  213. r GET key1{t}
  214. $rd GET key2{t}
  215. assert_equal 1 [$rd read] ; # Consume the GET reply
  216. $rd_sg INCR key1{t}
  217. $rd_sg INCR key2{t}
  218. set res1 [lindex [$rd_redirection read] 2]
  219. set res2 [lindex [$rd_redirection read] 2]
  220. assert {$res1 eq {key1{t}}}
  221. assert {$res2 eq {key2{t}}}
  222. }
  223. test {Different clients using different protocols can track the same key} {
  224. $rd HELLO 3
  225. set reply [$rd read] ; # Consume the HELLO reply
  226. assert_equal 3 [dict get $reply proto]
  227. $rd CLIENT TRACKING on
  228. assert_equal OK [$rd read] ; # Consume the TRACKING reply
  229. $rd_sg set key1 1
  230. r GET key1
  231. $rd GET key1
  232. assert_equal 1 [$rd read] ; # Consume the GET reply
  233. $rd_sg INCR key1
  234. set res1 [lindex [$rd_redirection read] 2]
  235. $rd PING ; # Non redirecting client has to talk to the server in order to get invalidation message
  236. set res2 [lindex [split [$rd read] " "] 1]
  237. assert_equal PONG [$rd read] ; # Consume the PING reply, which comes together with the invalidation message
  238. assert {$res1 eq {key1}}
  239. assert {$res2 eq {key1}}
  240. }
  241. test {No invalidation message when using OPTIN option} {
  242. r CLIENT TRACKING on OPTIN REDIRECT $redir_id
  243. $rd_sg SET key1 1
  244. r GET key1 ; # This key should not be notified, since OPTIN is on and CLIENT CACHING yes wasn't called
  245. $rd_sg SET key1 2
  246. # Preparing some message to consume on $rd_redirection so we don't get blocked
  247. r CLIENT TRACKING off
  248. r CLIENT TRACKING on REDIRECT $redir_id
  249. $rd_sg SET key2 1
  250. r GET key2 ; # This key should be notified
  251. $rd_sg SET key2 2
  252. set res [lindex [$rd_redirection read] 2]
  253. assert {$res eq {key2}}
  254. }
  255. test {Invalidation message sent when using OPTIN option with CLIENT CACHING yes} {
  256. r CLIENT TRACKING on OPTIN REDIRECT $redir_id
  257. $rd_sg SET key1 3
  258. r CLIENT CACHING yes
  259. r GET key1
  260. $rd_sg SET key1 4
  261. set res [lindex [$rd_redirection read] 2]
  262. assert {$res eq {key1}}
  263. }
  264. test {Invalidation message sent when using OPTOUT option} {
  265. r CLIENT TRACKING off
  266. r CLIENT TRACKING on OPTOUT REDIRECT $redir_id
  267. $rd_sg SET key1 1
  268. r GET key1
  269. $rd_sg SET key1 2
  270. set res [lindex [$rd_redirection read] 2]
  271. assert {$res eq {key1}}
  272. }
  273. test {No invalidation message when using OPTOUT option with CLIENT CACHING no} {
  274. $rd_sg SET key1 1
  275. r CLIENT CACHING no
  276. r GET key1 ; # This key should not be notified, since OPTOUT is on and CLIENT CACHING no was called
  277. $rd_sg SET key1 2
  278. # Preparing some message to consume on $rd_redirection so we don't get blocked
  279. $rd_sg SET key2 1
  280. r GET key2 ; # This key should be notified
  281. $rd_sg SET key2 2
  282. set res [lindex [$rd_redirection read] 2]
  283. assert {$res eq {key2}}
  284. }
  285. test {Able to redirect to a RESP3 client} {
  286. $rd_redirection UNSUBSCRIBE __redis__:invalidate ; # Need to unsub first before we can do HELLO 3
  287. set res [$rd_redirection read] ; # Consume the UNSUBSCRIBE reply
  288. assert_equal {__redis__:invalidate} [lindex $res 1]
  289. $rd_redirection HELLO 3
  290. set res [$rd_redirection read] ; # Consume the HELLO reply
  291. assert_equal [dict get $reply proto] 3
  292. $rd_redirection SUBSCRIBE __redis__:invalidate
  293. set res [$rd_redirection read] ; # Consume the SUBSCRIBE reply
  294. assert_equal {__redis__:invalidate} [lindex $res 1]
  295. r CLIENT TRACKING on REDIRECT $redir_id
  296. $rd_sg SET key1 1
  297. r GET key1
  298. $rd_sg INCR key1
  299. set res [lindex [$rd_redirection read] 1]
  300. assert {$res eq {key1}}
  301. $rd_redirection HELLO 2
  302. set res [$rd_redirection read] ; # Consume the HELLO reply
  303. assert_equal [dict get $res proto] 2
  304. }
  305. test {After switching from normal tracking to BCAST mode, no invalidation message is produced for pre-BCAST keys} {
  306. r CLIENT TRACKING off
  307. r HELLO 3
  308. r CLIENT TRACKING on
  309. $rd_sg SET key1 1
  310. r GET key1
  311. r CLIENT TRACKING off
  312. r CLIENT TRACKING on BCAST
  313. $rd_sg INCR key1
  314. set inv_msg [r PING]
  315. set ping_reply [r read]
  316. assert {$inv_msg eq {invalidate key1}}
  317. assert {$ping_reply eq {PONG}}
  318. }
  319. test {BCAST with prefix collisions throw errors} {
  320. set r [redis_client]
  321. catch {$r CLIENT TRACKING ON BCAST PREFIX FOOBAR PREFIX FOO} output
  322. assert_match {ERR Prefix 'FOOBAR'*'FOO'*} $output
  323. catch {$r CLIENT TRACKING ON BCAST PREFIX FOO PREFIX FOOBAR} output
  324. assert_match {ERR Prefix 'FOO'*'FOOBAR'*} $output
  325. $r CLIENT TRACKING ON BCAST PREFIX FOO PREFIX BAR
  326. catch {$r CLIENT TRACKING ON BCAST PREFIX FO} output
  327. assert_match {ERR Prefix 'FO'*'FOO'*} $output
  328. catch {$r CLIENT TRACKING ON BCAST PREFIX BARB} output
  329. assert_match {ERR Prefix 'BARB'*'BAR'*} $output
  330. $r CLIENT TRACKING OFF
  331. }
  332. test {Tracking gets notification on tracking table key eviction} {
  333. r CLIENT TRACKING off
  334. r CLIENT TRACKING on REDIRECT $redir_id NOLOOP
  335. r MSET key1{t} 1 key2{t} 2
  336. # Let the server track the two keys for us
  337. r MGET key1{t} key2{t}
  338. # Force the eviction of all the keys but one:
  339. r config set tracking-table-max-keys 1
  340. # Note that we may have other keys in the table for this client,
  341. # since we disabled/enabled tracking multiple time with the same
  342. # ID, and tracking does not do ID cleanups for performance reasons.
  343. # So we check that eventually we'll receive one or the other key,
  344. # otherwise the test will die for timeout.
  345. while 1 {
  346. set keys [lindex [$rd_redirection read] 2]
  347. if {$keys eq {key1{t}} || $keys eq {key2{t}}} break
  348. }
  349. # We should receive an expire notification for one of
  350. # the two keys (only one must remain)
  351. assert {$keys eq {key1{t}} || $keys eq {key2{t}}}
  352. }
  353. test {Invalidation message received for flushall} {
  354. clean_all
  355. r CLIENT TRACKING on REDIRECT $redir_id
  356. $rd_sg SET key1 1
  357. r GET key1
  358. $rd_sg FLUSHALL
  359. set msg [$rd_redirection read]
  360. assert {[lindex msg 2] eq {} }
  361. }
  362. test {Invalidation message received for flushdb} {
  363. clean_all
  364. r CLIENT TRACKING on REDIRECT $redir_id
  365. $rd_sg SET key1 1
  366. r GET key1
  367. $rd_sg FLUSHDB
  368. set msg [$rd_redirection read]
  369. assert {[lindex msg 2] eq {} }
  370. }
  371. test {Test ASYNC flushall} {
  372. clean_all
  373. r CLIENT TRACKING on REDIRECT $redir_id
  374. r GET key1
  375. r GET key2
  376. assert_equal [s 0 tracking_total_keys] 2
  377. $rd_sg FLUSHALL ASYNC
  378. assert_equal [s 0 tracking_total_keys] 0
  379. assert_equal [lindex [$rd_redirection read] 2] {}
  380. }
  381. # Keys are defined to be evicted 100 at a time by default.
  382. # If after eviction the number of keys still surpasses the limit
  383. # defined in tracking-table-max-keys, we increases eviction
  384. # effort to 200, and then 300, etc.
  385. # This test tests this effort incrementation.
  386. test {Server is able to evacuate enough keys when num of keys surpasses limit by more than defined initial effort} {
  387. clean_all
  388. set NUM_OF_KEYS_TO_TEST 250
  389. set TRACKING_TABLE_MAX_KEYS 1
  390. r CLIENT TRACKING on REDIRECT $redir_id
  391. for {set i 0} {$i < $NUM_OF_KEYS_TO_TEST} {incr i} {
  392. $rd_sg SET key$i $i
  393. r GET key$i
  394. }
  395. r config set tracking-table-max-keys $TRACKING_TABLE_MAX_KEYS
  396. # If not enough keys are evicted, we won't get enough invalidation
  397. # messages, and "$rd_redirection read" will block.
  398. # If too many keys are evicted, we will get too many invalidation
  399. # messages, and the assert will fail.
  400. for {set i 0} {$i < $NUM_OF_KEYS_TO_TEST - $TRACKING_TABLE_MAX_KEYS} {incr i} {
  401. $rd_redirection read
  402. }
  403. $rd_redirection PING
  404. assert {[$rd_redirection read] eq {pong {}}}
  405. }
  406. test {Tracking info is correct} {
  407. clean_all
  408. r CLIENT TRACKING on REDIRECT $redir_id
  409. $rd_sg SET key1 1
  410. $rd_sg SET key2 2
  411. r GET key1
  412. r GET key2
  413. $rd CLIENT TRACKING on BCAST PREFIX prefix:
  414. assert [string match *OK* [$rd read]]
  415. $rd_sg SET prefix:key1 1
  416. $rd_sg SET prefix:key2 2
  417. set info [r info]
  418. regexp "\r\ntracking_total_items:(.*?)\r\n" $info _ total_items
  419. regexp "\r\ntracking_total_keys:(.*?)\r\n" $info _ total_keys
  420. regexp "\r\ntracking_total_prefixes:(.*?)\r\n" $info _ total_prefixes
  421. regexp "\r\ntracking_clients:(.*?)\r\n" $info _ tracking_clients
  422. assert {$total_items == 2}
  423. assert {$total_keys == 2}
  424. assert {$total_prefixes == 1}
  425. assert {$tracking_clients == 2}
  426. }
  427. test {CLIENT GETREDIR provides correct client id} {
  428. set res [r CLIENT GETREDIR]
  429. assert_equal $redir_id $res
  430. r CLIENT TRACKING off
  431. set res [r CLIENT GETREDIR]
  432. assert_equal -1 $res
  433. r CLIENT TRACKING on
  434. set res [r CLIENT GETREDIR]
  435. assert_equal 0 $res
  436. }
  437. test {CLIENT TRACKINGINFO provides reasonable results when tracking off} {
  438. r CLIENT TRACKING off
  439. set res [r client trackinginfo]
  440. set flags [dict get $res flags]
  441. assert_equal {off} $flags
  442. set redirect [dict get $res redirect]
  443. assert_equal {-1} $redirect
  444. set prefixes [dict get $res prefixes]
  445. assert_equal {} $prefixes
  446. }
  447. test {CLIENT TRACKINGINFO provides reasonable results when tracking on} {
  448. r CLIENT TRACKING on
  449. set res [r client trackinginfo]
  450. set flags [dict get $res flags]
  451. assert_equal {on} $flags
  452. set redirect [dict get $res redirect]
  453. assert_equal {0} $redirect
  454. set prefixes [dict get $res prefixes]
  455. assert_equal {} $prefixes
  456. }
  457. test {CLIENT TRACKINGINFO provides reasonable results when tracking on with options} {
  458. r CLIENT TRACKING on REDIRECT $redir_id noloop
  459. set res [r client trackinginfo]
  460. set flags [dict get $res flags]
  461. assert_equal {on noloop} $flags
  462. set redirect [dict get $res redirect]
  463. assert_equal $redir_id $redirect
  464. set prefixes [dict get $res prefixes]
  465. assert_equal {} $prefixes
  466. }
  467. test {CLIENT TRACKINGINFO provides reasonable results when tracking optin} {
  468. r CLIENT TRACKING off
  469. r CLIENT TRACKING on optin
  470. set res [r client trackinginfo]
  471. set flags [dict get $res flags]
  472. assert_equal {on optin} $flags
  473. set redirect [dict get $res redirect]
  474. assert_equal {0} $redirect
  475. set prefixes [dict get $res prefixes]
  476. assert_equal {} $prefixes
  477. r CLIENT CACHING yes
  478. set res [r client trackinginfo]
  479. set flags [dict get $res flags]
  480. assert_equal {on optin caching-yes} $flags
  481. }
  482. test {CLIENT TRACKINGINFO provides reasonable results when tracking optout} {
  483. r CLIENT TRACKING off
  484. r CLIENT TRACKING on optout
  485. set res [r client trackinginfo]
  486. set flags [dict get $res flags]
  487. assert_equal {on optout} $flags
  488. set redirect [dict get $res redirect]
  489. assert_equal {0} $redirect
  490. set prefixes [dict get $res prefixes]
  491. assert_equal {} $prefixes
  492. r CLIENT CACHING no
  493. set res [r client trackinginfo]
  494. set flags [dict get $res flags]
  495. assert_equal {on optout caching-no} $flags
  496. }
  497. test {CLIENT TRACKINGINFO provides reasonable results when tracking bcast mode} {
  498. r CLIENT TRACKING off
  499. r CLIENT TRACKING on BCAST PREFIX foo PREFIX bar
  500. set res [r client trackinginfo]
  501. set flags [dict get $res flags]
  502. assert_equal {on bcast} $flags
  503. set redirect [dict get $res redirect]
  504. assert_equal {0} $redirect
  505. set prefixes [lsort [dict get $res prefixes]]
  506. assert_equal {bar foo} $prefixes
  507. r CLIENT TRACKING off
  508. r CLIENT TRACKING on BCAST
  509. set res [r client trackinginfo]
  510. set prefixes [dict get $res prefixes]
  511. assert_equal {{}} $prefixes
  512. }
  513. test {CLIENT TRACKINGINFO provides reasonable results when tracking redir broken} {
  514. clean_all
  515. r HELLO 3
  516. r CLIENT TRACKING on REDIRECT $redir_id
  517. $rd_sg SET key1 1
  518. r GET key1
  519. $rd_redirection QUIT
  520. assert_equal OK [$rd_redirection read]
  521. $rd_sg SET key1 2
  522. set res [lsearch -exact [r read] "tracking-redir-broken"]
  523. assert {$res >= 0}
  524. set res [r client trackinginfo]
  525. set flags [dict get $res flags]
  526. assert_equal {on broken_redirect} $flags
  527. set redirect [dict get $res redirect]
  528. assert_equal $redir_id $redirect
  529. set prefixes [dict get $res prefixes]
  530. assert_equal {} $prefixes
  531. }
  532. $rd_redirection close
  533. $rd close
  534. }