From f118be72d4aa6fddada4757e85abe80e2d605969 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Wed, 15 Mar 2017 09:47:15 +0100 Subject: Make sure to update generation before adding error config --- .../config/proxy/UpstreamConfigSubscriberTest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'config-proxy/src') 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)); -- cgit v1.2.3