Test: do not use the same name twice

In rare cases, the CertificateToolTests#testPromptingForInstanceInformation could try to use the same name multiple
times. This causes the test to fail with a message for an unknown prompt. This commit ensures no duplicates are added.

relates elastic/x-pack-elasticsearch#597

Original commit: elastic/x-pack-elasticsearch@ab8bb7ad50
This commit is contained in:
jaymode 2017-02-23 12:34:06 -05:00
parent db88cc458d
commit e61f87d5ff
1 changed files with 8 additions and 1 deletions

View File

@ -120,7 +120,14 @@ public class CertificateToolTests extends ESTestCase {
final int numberOfInstances = scaledRandomIntBetween(1, 12);
Map<String, Map<String, String>> instanceInput = new HashMap<>(numberOfInstances);
for (int i = 0; i < numberOfInstances; i++) {
final String name = getValidRandomInstanceName();
final String name;
while (true) {
String randomName = getValidRandomInstanceName();
if (instanceInput.containsKey(randomName) == false) {
name = randomName;
break;
}
}
Map<String, String> instanceInfo = new HashMap<>();
instanceInput.put(name, instanceInfo);
instanceInfo.put("ip", randomFrom("127.0.0.1", "::1", "192.168.1.1,::1", ""));