Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
test: fix tests to allow running in parallel (#352)
Browse files Browse the repository at this point in the history
Fixes #351
  • Loading branch information
chingor13 committed Feb 19, 2021
1 parent 90985e9 commit 496d941
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
Expand Up @@ -17,6 +17,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.google.cloud.ServiceOptions;
import com.google.cloud.gaming.v1.CreateGameServerConfigRequest;
Expand Down Expand Up @@ -159,12 +160,18 @@ public void getRealmTest() {
@Test
public void listRealmsTest() {
List<Realm> realms = Lists.newArrayList(realmsServiceClient.listRealms(PARENT).iterateAll());
assertEquals(1, realms.size());
assertEquals(REALM_NAME.toString(), realms.get(0).getName());
assertEquals(TIME_ZONE, realms.get(0).getTimeZone());
assertEquals(DESCRIPTION, realms.get(0).getDescription());
assertNotNull(realms.get(0).getCreateTime());
assertNotNull(realms.get(0).getEtag());
assertTrue(realms.size() > 0);
boolean found = false;
for (Realm realm : realms) {
if (REALM_NAME.toString().equals(realm.getName())) {
found = true;
assertEquals(TIME_ZONE, realm.getTimeZone());
assertEquals(DESCRIPTION, realm.getDescription());
assertNotNull(realm.getCreateTime());
assertNotNull(realm.getEtag());
}
}
assertTrue("expected to find realm by resource name", found);
}

@Test
Expand Down Expand Up @@ -258,9 +265,14 @@ public void listGameServerConfigsTest() {
.build();
List<GameServerConfig> gameServerConfigs =
Lists.newArrayList(configsServiceClient.listGameServerConfigs(request).iterateAll());
assertEquals(1, gameServerConfigs.size());
assertNotNull(gameServerConfigs.get(0).getCreateTime());
assertEquals(GAME_SERVER_CONFIG_NAME.toString(), gameServerConfigs.get(0).getName());
assertEquals(DESCRIPTION, gameServerConfigs.get(0).getDescription());
boolean found = false;
for (GameServerConfig gameServerConfig : gameServerConfigs) {
assertNotNull(gameServerConfig.getCreateTime());
if (GAME_SERVER_CONFIG_NAME.toString().equals(gameServerConfig.getName())) {
found = true;
assertEquals(DESCRIPTION, gameServerConfig.getDescription());
}
}
assertTrue("expected to find game servcer config by resource name", found);
}
}
Expand Up @@ -45,7 +45,7 @@ public class ClusterTests {
private static String parentName =
String.format("projects/%s/locations/%s", PROJECT_ID, REGION_ID);

private static String realmId = "realm-1";
private static String realmId = "realm-" + GameServicesTestUtil.UID;
private static String realmName = String.format("%s/realms/%s", parentName, realmId);

private static String clusterId = "cluster-1";
Expand Down
Expand Up @@ -41,7 +41,7 @@ public class DeploymentTests {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");

private static String parentName = String.format("projects/%s/locations/global", PROJECT_ID);
private static String deploymentId = "deployment-1";
private static String deploymentId = "deployment-" + GameServicesTestUtil.UID;
private static String deploymentName =
String.format("%s/gameServerDeployments/%s", parentName, deploymentId);

Expand Down
Expand Up @@ -27,12 +27,14 @@
import com.google.cloud.gaming.v1.RealmsServiceClient;
import com.google.cloud.gaming.v1.RealmsServiceClient.ListRealmsPagedResponse;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

class GameServicesTestUtil {
private static GameServerClustersServiceClient clustersClient;
private static GameServerDeploymentsServiceClient deploymentsClient;
private static RealmsServiceClient realmsClient;
static String UID = UUID.randomUUID().toString().substring(0, 8);

private static GameServerClustersServiceClient getClustersClient() throws IOException {
if (clustersClient == null) {
Expand Down
Expand Up @@ -44,7 +44,7 @@ public class RealmTests {
private static String parentName =
String.format("projects/%s/locations/%s", PROJECT_ID, REGION_ID);

private static String realmId = "realm-1";
private static String realmId = "realm-" + GameServicesTestUtil.UID;
private static String realmName = String.format("%s/realms/%s", parentName, realmId);

private final PrintStream originalOut = System.out;
Expand Down

0 comments on commit 496d941

Please sign in to comment.