Repository: etcd-io/etcd
File: tests/integration/cache_test.go (Go)

Code before:

	for _, tc := range testCases {
		tc := tc
		t.Run(tc.name, func(t *testing.T) {
			resp, err := reader.Get(ctx, tc.key, tc.opts...)
			if err != nil {
				t.Fatalf("Get(%q): %v", tc.key, err)
			}

			if diff := cmp.Diff(tc.wantKVs, resp.Kvs); diff != "" {
				t.Errorf("unexpected KVs (-want +got):\n%s", diff)
			}

			if resp.Header.Revision != tc.wantRevision {
				t.Errorf("Header.Revision=%d; want: %d", resp.Header.Revision, tc.wantRevision)
			}
		})
	}
}

func TestCacheWithPrefixGetOutOfScope(t *testing.T) {
	integration.BeforeTest(t)
	clus := integration.NewCluster(t, &integration.ClusterConfig{Size: 1})
	t.Cleanup(func() { clus.Terminate(t) })
	cli := clus.Client(0)
	c, err := cache.New(cli, "/foo")
	if err != nil {
		t.Fatalf("cache.New: %v", err)
	}
	defer c.Close()
	ctx := t.Context()
	if err := c.WaitReady(ctx); err != nil {
		t.Fatalf("cache.WaitReady: %v", err)
	}

	cases := []struct {
		name string
		key  string
		opts []clientv3.OpOption
	}{
		{
			name: "single key outside prefix",
			key:  "/bar/a",
			opts: []clientv3.OpOption{clientv3.WithSerializable()},
		},
		{
			name: "prefix() outside cache prefix",
			key:  "/bar",
			opts: []clientv3.OpOption{clientv3.WithSerializable(), clientv3.WithPrefix()},
		},
		{

Review comment (performance):
We need a similar test for progress notification for watch. Like in this setup we should be able to open a watch on cache and get progress notification.

Code after:
	expectedFooA := &mvccpb.KeyValue{
		Key:            []byte("/foo/a"),
		Value:          []byte("val"),
		CreateRevision: seedRev,
		ModRevision:    seedRev,
		Version:        1,
	}

	testCases := []struct {
		name         string
		key          string
		opts         []clientv3.OpOption
		wantKVs      []*mvccpb.KeyValue
		wantRevision int64
	}{
		{
			name:         "single key within cache prefix",
			key:          "/foo/a",
			opts:         []clientv3.OpOption{clientv3.WithSerializable()},
			wantKVs:      []*mvccpb.KeyValue{expectedFooA},
			wantRevision: latestRev,
		},
		{
			name:         "single key within cache prefix at latest/progress rev",
			key:          "/foo/a",
			opts:         []clientv3.OpOption{clientv3.WithSerializable(), clientv3.WithRev(latestRev)},
			wantKVs:      []*mvccpb.KeyValue{expectedFooA},
			wantRevision: latestRev,
		},
		{
			name:         "prefix query within cache prefix",
			key:          "/foo",
			opts:         []clientv3.OpOption{clientv3.WithSerializable(), clientv3.WithPrefix()},
			wantKVs:      []*mvccpb.KeyValue{expectedFooA},
			wantRevision: latestRev,
		},
		{
			name:         "prefix query within cache prefix at latest/progress rev",
			key:          "/foo",
			opts:         []clientv3.OpOption{clientv3.WithSerializable(), clientv3.WithPrefix(), clientv3.WithRev(latestRev)},
			wantKVs:      []*mvccpb.KeyValue{expectedFooA},
			wantRevision: latestRev,
		},
		{
			name:         "range query within cache prefix",
			key:          "/foo/a",
			opts:         []clientv3.OpOption{clientv3.WithSerializable(), clientv3.WithRange("/foo/b")},
			wantKVs:      []*mvccpb.KeyValue{expectedFooA},
			wantRevision: latestRev,
		},
		{