Skip to content

Commit

Permalink
Use the latest version of the concurrency endpoint (#250)
Browse files Browse the repository at this point in the history
Use /rest/v1.2/users/{username}/concurrency endpoint to retrieve concurrency usage.

See https://docs.saucelabs.com/dev/api/accounts/#get-user-concurrency.
  • Loading branch information
adrian256 authored Sep 20, 2022
1 parent db6e242 commit 6b980a8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/main/java/com/saucelabs/saucerest/SauceREST.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ protected URL buildBuildUrl(JobSource source, String endpoint) {
return buildEndpoint(apiServer, "v2/builds/" + source.name().toLowerCase(Locale.ROOT) + "/" + endpoint, "Builds URL");
}

protected URL appendToBaseURL(String endpoint, String urlDescription) {
return buildEndpoint(apiServer, endpoint, urlDescription);
}

private URL buildHarUrl(String jobId) {
return this.buildEDSURL(jobId + "/" + TestAsset.HAR.label);
}
Expand Down Expand Up @@ -1584,7 +1588,7 @@ public String getTunnelInformation(String tunnelId) {
* @return String (in JSON format) representing the concurrency information
*/
public String getConcurrency() {
URL restEndpoint = buildURL("users/" + username + "/concurrency");
URL restEndpoint = appendToBaseURL("/rest/v1.2/users/" + username + "/concurrency", "Get User Concurrency");
return retrieveResults(restEndpoint);
}

Expand Down
11 changes: 6 additions & 5 deletions src/test/java/com/saucelabs/saucerest/SauceRESTTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,13 @@ void testGetActivity() {
@Test
void testGetConcurrency() throws Exception {
urlConnection.setResponseCode(200);
urlConnection.setInputStream(getClass().getResource("/users_halkeye_concurrency.json").openStream());

String concurencyInfo = sauceREST.getConcurrency();
assertEquals(this.urlConnection.getRealURL().getPath(), "/rest/v1/users/" + this.sauceREST.getUsername() + "/concurrency");
urlConnection.setInputStream(getClass().getResource("/users_test_concurrency.json").openStream());
String concurrencyInfo = sauceREST.getConcurrency();
assertEquals("/rest/v1.2/users/" + this.sauceREST.getUsername() + "/concurrency", this.urlConnection.getRealURL().getPath());
assertNull(this.urlConnection.getRealURL().getQuery());
assertEquals(concurencyInfo, "{\"timestamp\": 1447392030.111457, \"concurrency\": {\"halkeye\": {\"current\": {\"overall\": 0, \"mac\": 0, \"manual\": 0}, \"remaining\": {\"overall\": 100, \"mac\": 100, \"manual\": 5}}}}");

String expectedConcurrencyInfo = "{\"timestamp\":1447392030.111457,\"concurrency\":{\"organization\":{\"current\":{\"vms\":1,\"rds\":0,\"mac_vms\":0},\"id\":\"ca8b135d2e7e456385344811e05d84a6\",\"allowed\":{\"vms\":100,\"rds\":2,\"mac_vms\":100}},\"team\":{\"current\":{\"vms\":1,\"rds\":0,\"mac_vms\":0},\"id\":\"7e3beebb84bf4efaadffbbbbe780f294\",\"allowed\":{\"vms\":100,\"rds\":2,\"mac_vms\":100}}}}";
assertEquals(expectedConcurrencyInfo, concurrencyInfo);
}

@Test
Expand Down
1 change: 0 additions & 1 deletion src/test/resources/users_halkeye_concurrency.json

This file was deleted.

1 change: 1 addition & 0 deletions src/test/resources/users_test_concurrency.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"timestamp":1447392030.111457,"concurrency":{"organization":{"current":{"vms":1,"rds":0,"mac_vms":0},"id":"ca8b135d2e7e456385344811e05d84a6","allowed":{"vms":100,"rds":2,"mac_vms":100}},"team":{"current":{"vms":1,"rds":0,"mac_vms":0},"id":"7e3beebb84bf4efaadffbbbbe780f294","allowed":{"vms":100,"rds":2,"mac_vms":100}}}}

0 comments on commit 6b980a8

Please sign in to comment.