Fix flaky e2e tests because of no idle runners

at startup.
This commit is contained in:
Maximilian Paß
2022-10-14 11:39:17 +01:00
parent 50c2adb386
commit 3e9606d1b9
2 changed files with 43 additions and 0 deletions

View File

@@ -94,6 +94,7 @@ func initNomad() {
return
}
createDefaultEnvironment()
waitForDefaultEnvironment()
}
func createDefaultEnvironment() {
@@ -123,6 +124,28 @@ func createDefaultEnvironment() {
}
}
func waitForDefaultEnvironment() {
path := helpers.BuildURL(api.BasePath, api.RunnersPath)
body := &dto.RunnerRequest{
ExecutionEnvironmentID: tests.DefaultEnvironmentIDAsInteger,
InactivityTimeout: 1,
}
var code int
const maxRetries = 60
for count := 0; count < maxRetries && code != http.StatusOK; count++ {
<-time.After(time.Second)
if resp, err := helpers.HTTPPostJSON(path, body); err == nil {
code = resp.StatusCode
log.WithField("count", count).WithField("statusCode", code).Info("Waiting for idle runners")
} else {
log.WithField("count", count).WithError(err).Warn("Waiting for idle runners")
}
}
if code != http.StatusOK {
log.Fatal("Failed to provide a runner")
}
}
func deleteE2EEnvironments() {
for _, id := range environmentIDs {
deleteEnvironment(&testing.T{}, id.ToString())