mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2025-12-23 06:15:47 +00:00
attempt to fix a test flake seen sometimes in CI
This commit is contained in:
committed by
Joshua Casey
parent
ae5aad178d
commit
df017f9267
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2021-2023 the Pinniped contributors. All Rights Reserved.
|
// Copyright 2021-2024 the Pinniped contributors. All Rights Reserved.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package integration
|
package integration
|
||||||
@@ -76,15 +76,16 @@ func TestFormPostHTML_Browser_Parallel(t *testing.T) {
|
|||||||
require.Equal(t, responseParams.Get("code"), actualCode)
|
require.Equal(t, responseParams.Get("code"), actualCode)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("timeout", func(t *testing.T) {
|
t.Run("timeout followed by eventual success", func(t *testing.T) {
|
||||||
browser := browsertest.OpenBrowser(t)
|
browser := browsertest.OpenBrowser(t)
|
||||||
|
|
||||||
// Serve the form_post template with successful parameters.
|
// Serve the form_post template with successful parameters.
|
||||||
responseParams := formpostRandomParams(t)
|
responseParams := formpostRandomParams(t)
|
||||||
formpostInitiate(t, browser, formpostTemplateServer(t, callbackURL, responseParams))
|
formpostInitiate(t, browser, formpostTemplateServer(t, callbackURL, responseParams))
|
||||||
|
|
||||||
// Sleep for longer than the two second timeout.
|
// Sleep for longer than the two-second timeout hardcoded in form_post.js.
|
||||||
// During this sleep we are blocking the callback from returning.
|
// During this sleep we are blocking the callback from returning because we
|
||||||
|
// have not yet called expectCallback().
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
|
|
||||||
// Assert that the timeout fires and we see the manual instructions.
|
// Assert that the timeout fires and we see the manual instructions.
|
||||||
@@ -92,7 +93,7 @@ func TestFormPostHTML_Browser_Parallel(t *testing.T) {
|
|||||||
require.Equal(t, responseParams.Get("code"), actualCode)
|
require.Equal(t, responseParams.Get("code"), actualCode)
|
||||||
|
|
||||||
// Now simulate the callback finally succeeding, in which case
|
// Now simulate the callback finally succeeding, in which case
|
||||||
// the manual instructions should disappear and we should see the success
|
// the manual instructions should disappear, and we should see the success
|
||||||
// div instead.
|
// div instead.
|
||||||
expectCallback(t, responseParams)
|
expectCallback(t, responseParams)
|
||||||
formpostExpectSuccessState(t, browser)
|
formpostExpectSuccessState(t, browser)
|
||||||
@@ -117,9 +118,7 @@ func formpostCallbackServer(t *testing.T) (string, func(*testing.T, url.Values))
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow CORS requests. This will be needed for this test in the future if we change
|
// Allow CORS requests.
|
||||||
// the Javascript code from using mode 'no-cors' to instead use mode 'cors'. At the
|
|
||||||
// moment it should be ignored by the browser.
|
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
|
||||||
assert.NoError(t, r.ParseForm())
|
assert.NoError(t, r.ParseForm())
|
||||||
@@ -132,8 +131,9 @@ func formpostCallbackServer(t *testing.T) (string, func(*testing.T, url.Values))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the form parameters back on the results channel, giving up if the
|
// Send the form parameters back on the results channel, blocking until the test calls
|
||||||
// request context is cancelled (such as if the client disconnects).
|
// the function returned by formpostCallbackServer() to read this message, but also
|
||||||
|
// giving up if the request context is cancelled (such as if the client disconnects).
|
||||||
select {
|
select {
|
||||||
case results <- postParams:
|
case results <- postParams:
|
||||||
case <-r.Context().Done():
|
case <-r.Context().Done():
|
||||||
@@ -235,9 +235,24 @@ func formpostExpectFavicon(t *testing.T, b *browsertest.Browser, expected string
|
|||||||
// loading animation to be shown.
|
// loading animation to be shown.
|
||||||
func formpostInitiate(t *testing.T, b *browsertest.Browser, url string) {
|
func formpostInitiate(t *testing.T, b *browsertest.Browser, url string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
t.Logf("navigating to mock form_post template URL %s...", url)
|
t.Logf("navigating to mock form_post template URL %s...", url)
|
||||||
|
navigationStartTime := time.Now()
|
||||||
b.Navigate(t, url)
|
b.Navigate(t, url)
|
||||||
|
|
||||||
|
// There is a race here, because the JS code will only show this loading animation
|
||||||
|
// for two seconds, and then will automatically hide it and instead show the manual
|
||||||
|
// copy/paste UI. So if this test runs on a very busy/slow machine that takes more
|
||||||
|
// than two seconds to start waiting for the loading div after opening the page,
|
||||||
|
// then it would fail. This is rare but does happen occasionally, so just skip these
|
||||||
|
// assertions in that case.
|
||||||
|
if time.Since(navigationStartTime) > 1500*time.Millisecond {
|
||||||
|
// Took too long to navigate to the page to be able to consistently see the
|
||||||
|
// loading animation, which is only supposed to last for 2 seconds.
|
||||||
|
t.Logf("skipping loading animation assertions because test was too slow...")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
t.Logf("expecting to see loading animation...")
|
t.Logf("expecting to see loading animation...")
|
||||||
b.WaitForVisibleElements(t, "div#loading")
|
b.WaitForVisibleElements(t, "div#loading")
|
||||||
require.Equal(t, "Logging in...", b.Title(t))
|
require.Equal(t, "Logging in...", b.Title(t))
|
||||||
|
|||||||
Reference in New Issue
Block a user