summaryrefslogtreecommitdiffstats
path: root/clustercontroller-core
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@oath.com>2018-04-27 16:15:08 +0200
committerTor Brede Vekterli <vekterli@oath.com>2018-04-27 16:15:08 +0200
commit707394d4760b9a37be0c04f28faef917c4b9aefa (patch)
treeb43f109c91e9d974594e6bac068256bf401ac649 /clustercontroller-core
parent60e8fe66fe97d9af1b864dc3612d0860edcd1fe4 (diff)
Avoid candidate state racing with published state in tests
Since the tests using `StateWaiter` expects to observe _both_ versioned and unversioned (candidate) states, we ignore candidate states iff they are equal to the versioned state we have already observed. Otherwise, tests waiting for a _versioned_ state risk never observing the version number itself (only a candidate following it) and hang until they time out.
Diffstat (limited to 'clustercontroller-core')
-rw-r--r--clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/StateWaiter.java15
1 files changed, 15 insertions, 0 deletions
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/StateWaiter.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/StateWaiter.java
index 7811e68c381..eb0ca6cff15 100644
--- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/StateWaiter.java
+++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/StateWaiter.java
@@ -37,6 +37,21 @@ public class StateWaiter implements SystemStateListener {
public void handleNewCandidateState(ClusterStateBundle states) {
// Treat candidate states as if they were published for the tests that use
// this (deprecated) waiter class.
+ //
+ // Since the tests using StateWaiter expects to observe _both_ versioned and
+ // unversioned (candidate) states, we ignore candidate states iff they are
+ // equal to the versioned state we have already observed. Otherwise, tests
+ // waiting for a _versioned_ state risk never observing the version number
+ // itself (only a candidate following it) and hang until they time out.
+ synchronized (timer) {
+ if (current != null) {
+ ClusterState versionPatchedState = states.getBaselineClusterState().clone();
+ versionPatchedState.setVersion(current.getVersion());
+ if (versionPatchedState.equals(current)) {
+ return;
+ }
+ }
+ }
handleNewPublishedState(states);
}