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@ab8bb7ad50d4e523dc4d568cf34d2d161dc709ec
@@ -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", ""));
