From 9b39c5bdbc13867919f7ab9ad770decee88abb4d Mon Sep 17 00:00:00 2001 From: Xumin <100666470+StarlightIbuki@users.noreply.github.com> Date: Fri, 8 Sep 2023 04:16:07 +0000 Subject: [PATCH] tests(*): yet another compilation of flakiness fixes (#11522) * chore(tests): update time for time sensitive tests * chore(tests): wait_until for flaky test --- .../01-cluster_events_spec.lua | 1 + .../25-oauth2/04-invalidations_spec.lua | 25 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/spec/02-integration/06-invalidations/01-cluster_events_spec.lua b/spec/02-integration/06-invalidations/01-cluster_events_spec.lua index 21751c985fa2..4103986781aa 100644 --- a/spec/02-integration/06-invalidations/01-cluster_events_spec.lua +++ b/spec/02-integration/06-invalidations/01-cluster_events_spec.lua @@ -288,6 +288,7 @@ for _, strategy in helpers.each_strategy() do end) it("broadcasts an event with a delay", function() + ngx.update_time() local cluster_events_1 = assert(kong_cluster_events.new { db = db, node_id = uuid_1, diff --git a/spec/03-plugins/25-oauth2/04-invalidations_spec.lua b/spec/03-plugins/25-oauth2/04-invalidations_spec.lua index 379167a6adec..90f7b25bf858 100644 --- a/spec/03-plugins/25-oauth2/04-invalidations_spec.lua +++ b/spec/03-plugins/25-oauth2/04-invalidations_spec.lua @@ -348,14 +348,23 @@ for _, strategy in helpers.each_strategy() do }) assert.res_status(200, res) - -- Check that cache is populated - local cache_key = db.oauth2_tokens:cache_key(token.access_token) - local res = assert(admin_client:send { - method = "GET", - path = "/cache/" .. cache_key, - headers = {} - }) - assert.res_status(200, res) + local cache_key + helpers.wait_until(function() + -- Check that cache is populated + cache_key = db.oauth2_tokens:cache_key(token.access_token) + local res = assert(admin_client:send { + method = "GET", + path = "/cache/" .. cache_key, + headers = {} + }) + + -- Discard body in case we need to retry. Otherwise the connection will mess up. + res:read_body() + if res.status ~= 200 then + assert.logfile().has.no.line("[error]", true) + end + return 200 == res.status + end, 5) local res = db.oauth2_tokens:select_by_access_token(token.access_token) local token_id = res.id