From c741c5d5793e8644398b08f9feb46a0db905270c Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Thu, 20 Apr 2023 17:22:39 +0000 Subject: [PATCH] test: change cfc test to make it work consistently Signed-off-by: Harshit Gangal --- go/vt/vtgate/executor_select_test.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/go/vt/vtgate/executor_select_test.go b/go/vt/vtgate/executor_select_test.go index 5e158ed4e2e..4aa51368be2 100644 --- a/go/vt/vtgate/executor_select_test.go +++ b/go/vt/vtgate/executor_select_test.go @@ -3913,12 +3913,24 @@ func TestSelectCFC(t *testing.T) { executor.normalize = true session := NewAutocommitSession(&vtgatepb.Session{}) - for i := 1; i < 100; i++ { - _, err := executor.Execute(context.Background(), "TestSelectCFC", session, - "select /*vt+ PLANNER=gen4 */ c2 from tbl_cfc where c1 like 'A%'", nil) - require.NoError(t, err) - assert.EqualValues(t, 1, executor.plans.Misses(), "missed count:") - assert.EqualValues(t, i-1, executor.plans.Hits(), "hit count:") + _, err := executor.Execute(context.Background(), "TestSelectCFC", session, + "select /*vt+ PLANNER=gen4 */ c2 from tbl_cfc where c1 like 'A%'", nil) + require.NoError(t, err) + + timeout := time.After(10 * time.Second) + for { + select { + case <-timeout: + t.Fatal("not able to cache a plan withing 10 seconds.") + case <-time.After(5 * time.Millisecond): + // should be able to find cache entry before the timeout. + cacheItems := executor.debugCacheEntries() + for _, item := range cacheItems { + if strings.Contains(item.Key, "c2 from tbl_cfc where c1 like") { + return + } + } + } } }