(t *testing.T, c *Client)
| 349 | } |
| 350 | |
| 351 | func testTouchWithClient(t *testing.T, c *Client) { |
| 352 | if testing.Short() { |
| 353 | t.Log("Skipping testing memcache Touch with testing in Short mode") |
| 354 | return |
| 355 | } |
| 356 | |
| 357 | mustSet := mustSetF(t, c) |
| 358 | |
| 359 | const secondsToExpiry = int32(2) |
| 360 | |
| 361 | // We will set foo and bar to expire in 2 seconds, then we'll keep touching |
| 362 | // foo every second |
| 363 | // After 3 seconds, we expect foo to be available, and bar to be expired |
| 364 | foo := &Item{Key: "foo", Value: []byte("fooval"), Expiration: secondsToExpiry} |
| 365 | bar := &Item{Key: "bar", Value: []byte("barval"), Expiration: secondsToExpiry} |
| 366 | |
| 367 | setTime := time.Now() |
| 368 | mustSet(foo) |
| 369 | mustSet(bar) |
| 370 | |
| 371 | for s := 0; s < 3; s++ { |
| 372 | time.Sleep(time.Duration(1 * time.Second)) |
| 373 | err := c.Touch(foo.Key, secondsToExpiry) |
| 374 | if nil != err { |
| 375 | t.Errorf("error touching foo: %v", err.Error()) |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | _, err := c.Get("foo") |
| 380 | if err != nil { |
| 381 | if err == ErrCacheMiss { |
| 382 | t.Fatalf("touching failed to keep item foo alive") |
| 383 | } else { |
| 384 | t.Fatalf("unexpected error retrieving foo after touching: %v", err.Error()) |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | _, err = c.Get("bar") |
| 389 | if err == nil { |
| 390 | t.Fatalf("item bar did not expire within %v seconds", time.Now().Sub(setTime).Seconds()) |
| 391 | } else { |
| 392 | if err != ErrCacheMiss { |
| 393 | t.Fatalf("unexpected error retrieving bar: %v", err.Error()) |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | func BenchmarkOnItem(b *testing.B) { |
| 399 | fakeServer, err := net.Listen("tcp", "localhost:0") |
no test coverage detected
searching dependent graphs…