Skip to content

Commit a74d803

Browse files
authored
browser: fix web vitals test flakiness on Windows (#4630)
* browser: fix web vitals test flakiness on Windows The TestWebVitalMetricNoInteraction test was failing on Windows due to timing issues when collecting web vital metrics. This commit: - Increases timeout from 5s to 10s specifically for Windows - Adds a 1s delay after page load to ensure metrics are collected - Uses explicit timeout values instead of DefaultTimeout These changes make the test more reliable on Windows while maintaining the same behavior on other platforms. * Standardize web vital test timeouts
1 parent 70df5ca commit a74d803

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

internal/js/modules/k6/browser/tests/webvital_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func TestWebVitalMetricNoInteraction(t *testing.T) {
106106
)
107107

108108
done := make(chan struct{})
109-
ctx, cancel := context.WithTimeout(browser.context(), 5*time.Second)
109+
ctx, cancel := context.WithTimeout(browser.context(), common.DefaultTimeout)
110110
defer cancel()
111111
go func() {
112112
for {
@@ -127,9 +127,9 @@ func TestWebVitalMetricNoInteraction(t *testing.T) {
127127
}
128128
}()
129129

130-
// wait until the page is completely loaded.
131130
page := browser.NewPage(nil)
132131
opts := &common.FrameGotoOptions{
132+
// Wait for both load and network idle events
133133
WaitUntil: common.LifecycleEventNetworkIdle,
134134
Timeout: common.DefaultTimeout,
135135
}
@@ -140,6 +140,9 @@ func TestWebVitalMetricNoInteraction(t *testing.T) {
140140
require.NoError(t, err)
141141
require.NotNil(t, resp)
142142

143+
// Add a small delay to ensure all metrics are collected
144+
time.Sleep(1 * time.Second)
145+
143146
// prevents `err:fetching response body: context canceled` warning.`
144147
require.NoError(t, page.Close())
145148
done <- struct{}{}

0 commit comments

Comments
 (0)