@@ -65,6 +65,9 @@ func TestGalaxycacheGetWithPeek(t *testing.T) {
6565 includeSelf bool
6666 setClock time.Time
6767
68+ getTTL , peekTTL time.Duration
69+ getTTLJitter , peekTTLJitter time.Duration
70+
6871 expiry time.Time
6972
7073 // getter for locally fetched values (may call t.Error/Errorf,
@@ -194,6 +197,132 @@ func TestGalaxycacheGetWithPeek(t *testing.T) {
194197 peer1Addr : 1 ,
195198 peer2Addr : 1 ,
196199 },
200+ }, {
201+ name : "peeks_hit_each_peer_with_expiry_capped_getTTL" ,
202+ includePeers : []int {0 , 1 , 2 },
203+ includeSelf : true ,
204+ setClock : baseTime ,
205+ expiry : baseTime .Add (time .Hour * 84 ),
206+ getTTL : time .Hour * 30 ,
207+ localGetter : func (t testing.TB , key string ) (string , BackendGetInfo , error ) {
208+ t .Errorf ("unexpected local fetch (peek should succeed on peer)" )
209+ return "" , BackendGetInfo {}, fmt .Errorf ("unexpected call" )
210+ },
211+ peekModes : map [string ]testPeekMode {
212+ peer0Addr : testPeekModeHit ,
213+ peer1Addr : testPeekModeHit ,
214+ peer2Addr : testPeekModeHit ,
215+ },
216+ checkSteps : []checkStep {
217+ {
218+ key : chtest .FallthroughKey (self , peer0 ),
219+ expVal : peer0Addr + ": peek got: " + chtest .FallthroughKey (self , peer0 ),
220+ expExpiry : baseTime .Add (time .Hour * 30 ),
221+ },
222+ {
223+ // second fetch, since the key should now be in the main cache
224+ key : chtest .FallthroughKey (self , peer0 ),
225+ expVal : peer0Addr + ": peek got: " + chtest .FallthroughKey (self , peer0 ),
226+ getOpts : GetOptions {
227+ FetchMode : FetchModePeek ,
228+ },
229+ expExpiry : baseTime .Add (time .Hour * 30 ),
230+ },
231+ {
232+ key : chtest .FallthroughKey (self , peer1 ),
233+ expVal : peer1Addr + ": peek got: " + chtest .FallthroughKey (self , peer1 ),
234+ expExpiry : baseTime .Add (time .Hour * 30 ),
235+ },
236+ {
237+ key : chtest .FallthroughKey (self , peer1 ),
238+ expVal : peer1Addr + ": peek got: " + chtest .FallthroughKey (self , peer1 ),
239+ getOpts : GetOptions {
240+ FetchMode : FetchModePeek ,
241+ },
242+ expExpiry : baseTime .Add (time .Hour * 30 ),
243+ },
244+ {
245+ key : chtest .FallthroughKey (self , peer2 ),
246+ expVal : peer2Addr + ": peek got: " + chtest .FallthroughKey (self , peer2 ),
247+ expExpiry : baseTime .Add (time .Hour * 30 ),
248+ },
249+ {
250+ key : chtest .FallthroughKey (self , peer2 ),
251+ expVal : peer2Addr + ": peek got: " + chtest .FallthroughKey (self , peer2 ),
252+ getOpts : GetOptions {
253+ FetchMode : FetchModePeek ,
254+ },
255+ expExpiry : baseTime .Add (time .Hour * 30 ),
256+ },
257+ },
258+ expPeeks : map [string ]int {
259+ peer0Addr : 1 ,
260+ peer1Addr : 1 ,
261+ peer2Addr : 1 ,
262+ },
263+ }, {
264+ name : "peeks_hit_each_peer_with_expiry_capped_peekTTL" ,
265+ includePeers : []int {0 , 1 , 2 },
266+ includeSelf : true ,
267+ setClock : baseTime ,
268+ expiry : baseTime .Add (time .Hour * 84 ),
269+ peekTTL : time .Hour * 30 ,
270+ localGetter : func (t testing.TB , key string ) (string , BackendGetInfo , error ) {
271+ t .Errorf ("unexpected local fetch (peek should succeed on peer)" )
272+ return "" , BackendGetInfo {}, fmt .Errorf ("unexpected call" )
273+ },
274+ peekModes : map [string ]testPeekMode {
275+ peer0Addr : testPeekModeHit ,
276+ peer1Addr : testPeekModeHit ,
277+ peer2Addr : testPeekModeHit ,
278+ },
279+ checkSteps : []checkStep {
280+ {
281+ key : chtest .FallthroughKey (self , peer0 ),
282+ expVal : peer0Addr + ": peek got: " + chtest .FallthroughKey (self , peer0 ),
283+ expExpiry : baseTime .Add (time .Hour * 30 ),
284+ },
285+ {
286+ // second fetch, since the key should now be in the main cache
287+ key : chtest .FallthroughKey (self , peer0 ),
288+ expVal : peer0Addr + ": peek got: " + chtest .FallthroughKey (self , peer0 ),
289+ getOpts : GetOptions {
290+ FetchMode : FetchModePeek ,
291+ },
292+ expExpiry : baseTime .Add (time .Hour * 30 ),
293+ },
294+ {
295+ key : chtest .FallthroughKey (self , peer1 ),
296+ expVal : peer1Addr + ": peek got: " + chtest .FallthroughKey (self , peer1 ),
297+ expExpiry : baseTime .Add (time .Hour * 30 ),
298+ },
299+ {
300+ key : chtest .FallthroughKey (self , peer1 ),
301+ expVal : peer1Addr + ": peek got: " + chtest .FallthroughKey (self , peer1 ),
302+ getOpts : GetOptions {
303+ FetchMode : FetchModePeek ,
304+ },
305+ expExpiry : baseTime .Add (time .Hour * 30 ),
306+ },
307+ {
308+ key : chtest .FallthroughKey (self , peer2 ),
309+ expVal : peer2Addr + ": peek got: " + chtest .FallthroughKey (self , peer2 ),
310+ expExpiry : baseTime .Add (time .Hour * 30 ),
311+ },
312+ {
313+ key : chtest .FallthroughKey (self , peer2 ),
314+ expVal : peer2Addr + ": peek got: " + chtest .FallthroughKey (self , peer2 ),
315+ getOpts : GetOptions {
316+ FetchMode : FetchModePeek ,
317+ },
318+ expExpiry : baseTime .Add (time .Hour * 30 ),
319+ },
320+ },
321+ expPeeks : map [string ]int {
322+ peer0Addr : 1 ,
323+ peer1Addr : 1 ,
324+ peer2Addr : 1 ,
325+ },
197326 }, {
198327 name : "peeks_timeout_each_peer" ,
199328 includePeers : []int {0 , 1 , 2 },
@@ -653,7 +782,7 @@ func TestGalaxycacheGetWithPeek(t *testing.T) {
653782 g := u .NewGalaxyWithBackendInfo ("easy come; easy go" , 256 , getter , WithPreviousPeerPeeking (PeekPeerCfg {
654783 WarmTime : warmPeriod ,
655784 PeekTimeout : peekTimeout },
656- ))
785+ ), WithGetTTL ( tbl . getTTL , tbl . getTTLJitter ), WithPeekTTL ( tbl . peekTTL , tbl . peekTTLJitter ) )
657786
658787 fc .SetClock (tbl .setClock )
659788 ctx , cancel := context .WithCancel (context .Background ())
@@ -687,7 +816,7 @@ func TestGalaxycacheGetWithPeek(t *testing.T) {
687816 t .Errorf ("unexpected error fetching step %d; key %q: %s" , i , step .key , getErr )
688817 continue
689818 } else if ! getInfo .Expiry .Equal (step .expExpiry ) {
690- t .Errorf ("unexpected expiry: %s; expected %s" , getInfo .Expiry , step .expExpiry )
819+ t .Errorf ("step %d: unexpected expiry: %s; expected %s" , i , getInfo .Expiry , step .expExpiry )
691820 }
692821 if string (c ) != step .expVal {
693822 t .Errorf ("unexpected value for key %q in step %d\n want: %q\n got %q" , step .key , i , step .expVal , c )
0 commit comments