From e395573c98354169e7ba94a0bbd5fef6117be919 Mon Sep 17 00:00:00 2001 From: "arthur.barr@uk.ibm.com" Date: Tue, 2 Aug 2022 16:44:01 +0100 Subject: [PATCH] Allow for slow standby take-over in MIQM test (backport) In TestMultiInstanceContainerStop, if the standby hasn't taken over by the time the active has stopped, the test fails. This causes problems on slow machines for the CI/CD pipeline. This commit adds a 30 second timeout on the take-over. --- test/docker/mq_multi_instance_test.go | 24 +++++++++++++++++----- test/docker/mq_multi_instance_test_util.go | 3 ++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/test/docker/mq_multi_instance_test.go b/test/docker/mq_multi_instance_test.go index fb5da059..b0c08501 100644 --- a/test/docker/mq_multi_instance_test.go +++ b/test/docker/mq_multi_instance_test.go @@ -1,5 +1,5 @@ /* -© Copyright IBM Corporation 2019, 2020 +© Copyright IBM Corporation 2019, 2023 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ limitations under the License. package main import ( + "context" "strings" "testing" "time" @@ -92,15 +93,28 @@ func TestMultiInstanceContainerStop(t *testing.T) { waitForReady(t, cli, qm1aId) waitForReady(t, cli, qm1bId) - err, active, standby := getActiveStandbyQueueManager(t, cli, qm1aId, qm1bId) + err, originalActive, originalStandby := getActiveStandbyQueueManager(t, cli, qm1aId, qm1bId) if err != nil { t.Fatal(err) } - stopContainer(t, cli, active) + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + stopContainer(t, cli, originalActive) - if status := getQueueManagerStatus(t, cli, standby, "QM1"); strings.Compare(status, "Running") != 0 { - t.Fatalf("Expected QM1 to be running as active queue manager, dspmq returned status of %v", status) + for { + status := getQueueManagerStatus(t, cli, originalStandby, "QM1") + select { + case <-time.After(1 * time.Second): + if status == "Running" { + t.Logf("Original standby is now the active") + return + } else if status == "Starting" { + t.Logf("Original standby is starting") + } + case <-ctx.Done(): + t.Fatalf("%s Timed out waiting for standby to become the active. Status=%v", time.Now().Format(time.RFC3339), status) + } } } diff --git a/test/docker/mq_multi_instance_test_util.go b/test/docker/mq_multi_instance_test_util.go index 6dfde7db..bf3993ff 100644 --- a/test/docker/mq_multi_instance_test_util.go +++ b/test/docker/mq_multi_instance_test_util.go @@ -1,5 +1,5 @@ /* -© Copyright IBM Corporation 2019 +© Copyright IBM Corporation 2019, 2023 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -77,6 +77,7 @@ func getActiveStandbyQueueManager(t *testing.T, cli *client.Client, qm1aId strin func getQueueManagerStatus(t *testing.T, cli *client.Client, containerID string, queueManagerName string) string { _, dspmqOut := execContainer(t, cli, containerID, "", []string{"bash", "-c", "dspmq", "-m", queueManagerName}) + t.Logf("dspmq for %v (%v) returned: %v", containerID, queueManagerName, dspmqOut) regex := regexp.MustCompile(`STATUS\(.*\)`) status := regex.FindString(dspmqOut) status = strings.TrimSuffix(strings.TrimPrefix(status, "STATUS("), ")")