Skip to content

Commit

Permalink
Fix IdentificationHelperTest
Browse files Browse the repository at this point in the history
Could fail if a previous test already initialized the helper
  • Loading branch information
Kay committed Sep 24, 2021
1 parent 31a8713 commit cd91681
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/*******************************************************************************
* Copyright (c) 2018 Oak Ridge National Laboratory.
* Copyright (c) 2018-2021 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.phoebus.applications.alarm.client;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.util.concurrent.TimeUnit;

Expand All @@ -27,16 +26,19 @@ public void testUserHost() throws Exception
String user = IdentificationHelper.getUser();
String host = IdentificationHelper.getHost();
System.out.println("User: '" + user + "' at host: '" + host + "'");
assertThat(user, equalTo("???"));
assertThat(host, equalTo("???"));
if ("???".equals(user) && "???".equals(host))
{
System.out.println("Initializing IdentificationHelper");
IdentificationHelper.initialize();
}
// else: Some other test that ran first already triggered initialization

// On successful initilization, there should soon be information
IdentificationHelper.initialize();
// On successful initialization, there should soon be information
int wait = 0;
while (host.equals("???"))
{
++wait;
assertThat("Timed out waiting for information", wait < 10, equalTo(true));
assertTrue("Timed out waiting for information", wait < 10);
TimeUnit.SECONDS.sleep(1);
user = IdentificationHelper.getUser();
host = IdentificationHelper.getHost();
Expand Down

0 comments on commit cd91681

Please sign in to comment.