diff options
author | Valerij Fredriksen <freva@users.noreply.github.com> | 2017-03-15 10:28:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-15 10:28:03 +0100 |
commit | a563306957b180c933e5e2ff68a989b32f02aae7 (patch) | |
tree | fd9c3d2d9e82ed89c783aadf861dc553872a470d | |
parent | f111ab07d4edc8a1640ed87b74162f6d3b99ad71 (diff) | |
parent | f118be72d4aa6fddada4757e85abe80e2d605969 (diff) |
Merge pull request #2006 from yahoo/musum/fix-test
Make sure to update generation before adding error config
-rw-r--r-- | config-proxy/src/test/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriberTest.java | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriberTest.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriberTest.java index 4a6858cfb19..138c54a3a16 100644 --- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriberTest.java +++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriberTest.java @@ -10,12 +10,13 @@ import com.yahoo.vespa.config.util.ConfigUtils; import org.junit.*; import org.junit.rules.TemporaryFolder; +import java.time.Duration; +import java.time.Instant; import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; import static junit.framework.TestCase.assertNotNull; -import static junit.framework.TestCase.fail; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -81,6 +82,7 @@ public class UpstreamConfigSubscriberTest { sourceResponses.put(fooConfig.getKey(), fooConfig); // Create config with error based on fooConfig + generation++; ConfigPayload errorConfigPayload = new ConfigPayload(new Slime()); Payload errorPayload = Payload.from(errorConfigPayload); ConfigKey<?> errorConfigKey = new ConfigKey<>("error", fooConfig.getConfigId(), fooConfig.getNamespace()); @@ -92,7 +94,7 @@ public class UpstreamConfigSubscriberTest { UpstreamConfigSubscriber subscriber = createUpstreamConfigSubscriber(errorConfig); waitForConfigGeneration(clientUpdater, errorConfigKey, generation); RawConfig lastConfig = clientUpdater.getLastConfig(); - assertEquals(lastConfig, errorConfig); + assertEquals(errorConfig, lastConfig); assertThat(lastConfig.errorCode(), is(ErrorCode.UNKNOWN_DEFINITION)); subscriber.cancel(); } @@ -106,13 +108,11 @@ public class UpstreamConfigSubscriberTest { } private void waitForConfigGeneration(MockClientUpdater clientUpdater, ConfigKey<?> configKey, long expectedGeneration) { - int i = 0; + Instant end = Instant.now().plus(Duration.ofSeconds(60)); RawConfig lastConfig; do { lastConfig = clientUpdater.getLastConfig(); - if (lastConfig != null) { - System.out.println("i=" + i + ", config=" + lastConfig + ",generation=" + lastConfig.getGeneration()); - } + System.out.println("config=" + lastConfig + (lastConfig == null ? "" : ",generation=" + lastConfig.getGeneration())); if (lastConfig != null && lastConfig.getKey().equals(configKey) && lastConfig.getGeneration() == expectedGeneration) { break; @@ -120,11 +120,11 @@ public class UpstreamConfigSubscriberTest { try { Thread.sleep(10); } catch (InterruptedException e) { - fail(e.getMessage()); + throw new RuntimeException(e); } } - i++; - } while (i < 5000); + } while (Instant.now().isBefore(end)); + assertNotNull(lastConfig); assertThat(lastConfig.getGeneration(), is(expectedGeneration)); assertThat(lastConfig.getKey(), is(configKey)); |