From fc23201ac4a70e404e9319c9f2b7d2af1b0d0caa Mon Sep 17 00:00:00 2001 From: ankur22 Date: Mon, 8 Apr 2024 11:33:10 +0100 Subject: [PATCH] Fix web vital trace test Instead of a sleep to wait for a web vital, which may be delayed for various reasons, and can cause the sub test to fail, catch the web vital spans that are emitted/received when the page.close() API is called. --- tests/tracing_test.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/tracing_test.go b/tests/tracing_test.go index f095db81a..b0bcb8440 100644 --- a/tests/tracing_test.go +++ b/tests/tracing_test.go @@ -107,13 +107,6 @@ func TestTracing(t *testing.T) { "navigation", }, }, - { - name: "web_vital", - js: "sleep(100);", // Wait for async WebVitals processing - spans: []string{ - "web_vital", - }, - }, { name: "page.screenshot", js: "page.screenshot();", @@ -147,14 +140,17 @@ func TestTracing(t *testing.T) { }, }, { - name: "page.close", - js: "page.close()", + name: "web_vital", + js: "page.close();", // on page.close, web vitals are collected and fired/received. spans: []string{ + "web_vital", "page.close", }, }, } + // Each sub test depends on the previous sub test, so they cannot be ran + // in parallel. for _, tc := range testCases { assertJSInEventLoop(t, vu, tc.js)