| 18 | ) |
| 19 | |
| 20 | func TestMemcachedClient_SetAsync(t *testing.T) { |
| 21 | t.Run("with non-zero TTL", func(t *testing.T) { |
| 22 | client, _, err := setupDefaultMemcachedClient() |
| 23 | require.NoError(t, err) |
| 24 | client.SetAsync("foo", []byte("bar"), 10*time.Second) |
| 25 | require.NoError(t, client.wait()) |
| 26 | |
| 27 | ctx := context.Background() |
| 28 | res := client.GetMulti(ctx, []string{"foo"}) |
| 29 | require.Equal(t, map[string][]byte{"foo": []byte("bar")}, res) |
| 30 | }) |
| 31 | |
| 32 | t.Run("with truncated zero TTL", func(t *testing.T) { |
| 33 | client, _, err := setupDefaultMemcachedClient() |
| 34 | require.NoError(t, err) |
| 35 | client.SetAsync("foo", []byte("bar"), 100*time.Millisecond) |
| 36 | require.NoError(t, client.wait()) |
| 37 | |
| 38 | ctx := context.Background() |
| 39 | res := client.GetMulti(ctx, []string{"foo"}) |
| 40 | require.Empty(t, res) |
| 41 | }) |
| 42 | |
| 43 | t.Run("with zero TTL", func(t *testing.T) { |
| 44 | client, _, err := setupDefaultMemcachedClient() |
| 45 | require.NoError(t, err) |
| 46 | client.SetAsync("foo", []byte("bar"), 0) |
| 47 | require.NoError(t, client.wait()) |
| 48 | |
| 49 | ctx := context.Background() |
| 50 | res := client.GetMulti(ctx, []string{"foo"}) |
| 51 | require.Equal(t, map[string][]byte{"foo": []byte("bar")}, res) |
| 52 | }) |
| 53 | } |
| 54 | |
| 55 | func TestMemcachedClient_Set(t *testing.T) { |
| 56 | t.Run("with non-zero TTL", func(t *testing.T) { |