Skip to content

Commit

Permalink
Reduce sleep time during integration tests; run CI tests in series
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Sep 23, 2019
1 parent 80e374e commit 5449a07
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 63 deletions.
15 changes: 6 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ commands:
- vendor
run-tests:
steps:
- run: ./vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml
- run: composer test-ci
- store_artifacts:
path: build/coverage.xml

Expand Down Expand Up @@ -58,17 +58,14 @@ jobs:
fi
when: always

#Each workflow represents a Github check
# Each workflow represents a Github check
workflows:
build_php_5:
build-and-test:
jobs:
- php_5
build_php_7:
jobs:
- php_7
snyk:
jobs:
- php_7
- php_7:
requires:
- php_5
- snyk:
# Must define SNYK_TOKEN env
context: snyk-env
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"scripts": {
"test": "SHELL_INTERACTIVE=1 \"vendor/bin/phpunit\" --coverage-text ",
"test-ci": "\"vendor/bin/phpunit\" --coverage-clover=build/coverage.xml",
"test-ci": "\"vendor/bin/phpunit\" --stop-on-failure --coverage-clover=build/coverage.xml",
"phpcs": "\"vendor/bin/phpcs\"",
"phpcbf": "\"vendor/bin/phpcbf\"",
"sniffs": "\"vendor/bin/phpcs\" -e",
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<phpunit
colors="true"
verbose="true"
stopOnFailure="true"
bootstrap="./tests/bootstrap.php">
<testsuites>
<testsuite name="Auth0 PHP SDK Test Suite">
Expand Down
4 changes: 2 additions & 2 deletions tests/API/Management/BlacklistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public function testBlacklistAndGet()
$test_jti = uniqid().uniqid().uniqid();

$api->blacklists()->blacklist($env['APP_CLIENT_ID'], $test_jti);
usleep(700000);
usleep(150000);

$blacklisted = $api->blacklists()->getAll($env['APP_CLIENT_ID']);
usleep(700000);
usleep(150000);

$this->assertGreaterThan( 0, count( $blacklisted ) );
$this->assertEquals( $env['APP_CLIENT_ID'], $blacklisted[0]['aud'] );
Expand Down
22 changes: 11 additions & 11 deletions tests/API/Management/ClientGrantsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function setUpBeforeClass()

self::$apiIdentifier = 'TEST_PHP_SDK_CLIENT_GRANT_API_'.uniqid();
$api->resourceServers()->create(self::$apiIdentifier, $create_data);
usleep(700000);
usleep(150000);
}

public function setUp()
Expand All @@ -82,7 +82,7 @@ public static function tearDownAfterClass()
parent::tearDownAfterClass();
$api = new Management(self::$env['API_TOKEN'], self::$env['DOMAIN']);
$api->resourceServers()->delete( self::$apiIdentifier );
usleep(700000);
usleep(150000);
}

/**
Expand All @@ -96,7 +96,7 @@ public static function tearDownAfterClass()
public function testGet()
{
$all_results = self::$api->getAll();
usleep(700000);
usleep(150000);
$this->assertNotEmpty($all_results);

$expected_client_id = $all_results[0]['client_id'] ?: null;
Expand All @@ -106,12 +106,12 @@ public function testGet()
$this->assertNotNull($expected_audience);

$audience_results = self::$api->getByAudience($expected_audience);
usleep(700000);
usleep(150000);
$this->assertNotEmpty($audience_results);
$this->assertEquals($expected_audience, $audience_results[0]['audience']);

$client_id_results = self::$api->getByClientId($expected_client_id);
usleep(700000);
usleep(150000);
$this->assertNotEmpty($client_id_results);
$this->assertEquals($expected_client_id, $client_id_results[0]['client_id']);
}
Expand All @@ -128,12 +128,12 @@ public function testGetWithPagination()
$expected_count = 2;

$results_1 = self::$api->getAll([], 0, $expected_count);
usleep(700000);
usleep(150000);
$this->assertCount($expected_count, $results_1);

$expected_page = 1;
$results_2 = self::$api->getAll([], $expected_page, 1);
usleep(700000);
usleep(150000);
$this->assertCount(1, $results_2);
$this->assertEquals($results_1[$expected_page]['client_id'], $results_2[0]['client_id']);
$this->assertEquals($results_1[$expected_page]['audience'], $results_2[0]['audience']);
Expand All @@ -152,7 +152,7 @@ public function testGetAllIncludeTotals()
$expected_count = 2;

$results = self::$api->getAll(['include_totals' => true], $expected_page, $expected_count);
usleep(700000);
usleep(150000);
$this->assertArrayHasKey('total', $results);
$this->assertEquals($expected_page * $expected_count, $results['start']);
$this->assertEquals($expected_count, $results['limit']);
Expand All @@ -174,7 +174,7 @@ public function testCreateUpdateDeleteGrant()

// Create a Client Grant with just one of the testing scopes.
$create_result = self::$api->create($client_id, $audience, [self::$scopes[0]]);
usleep(700000);
usleep(150000);
$this->assertArrayHasKey('id', $create_result);
$this->assertEquals($client_id, $create_result['client_id']);
$this->assertEquals($audience, $create_result['audience']);
Expand All @@ -184,12 +184,12 @@ public function testCreateUpdateDeleteGrant()

// Test patching the created Client Grant.
$update_result = self::$api->update($grant_id, self::$scopes);
usleep(700000);
usleep(150000);
$this->assertEquals(self::$scopes, $update_result['scope']);

// Test deleting the created Client Grant.
$delete_result = self::$api->delete($grant_id);
usleep(700000);
usleep(150000);
$this->assertNull($delete_result);
}

Expand Down
12 changes: 6 additions & 6 deletions tests/API/Management/ClientsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,15 @@ public function testIntegrationCreateGetUpdateDelete()
];

$created_client = $api->clients()->create($create_body);
usleep(700000);
usleep(150000);

$this->assertNotEmpty($created_client['client_id']);
$this->assertEquals($create_body['name'], $created_client['name']);
$this->assertEquals($create_body['app_type'], $created_client['app_type']);

$created_client_id = $created_client['client_id'];
$got_entity = $api->clients()->get($created_client_id);
usleep(700000);
usleep(150000);

// Make sure what we got matches what we created.
$this->assertEquals($created_client_id, $got_entity['client_id']);
Expand All @@ -230,14 +230,14 @@ public function testIntegrationCreateGetUpdateDelete()
];

$updated_client = $api->clients()->update($created_client_id, $update_body );
usleep(700000);
usleep(150000);

$this->assertEquals($created_client_id, $updated_client['client_id']);
$this->assertEquals($update_body['name'], $updated_client['name']);
$this->assertEquals($update_body['app_type'], $updated_client['app_type']);

$api->clients()->delete($created_client_id);
usleep(700000);
usleep(150000);
}

/**
Expand All @@ -257,7 +257,7 @@ public function testIntegrationGetAllMethod()

// Get the second page of Clients with 1 per page (second result).
$paged_results = $api->clients()->getAll($fields, true, $page_num, 1);
usleep(700000);
usleep(150000);

// Make sure we only have one result, as requested.
$this->assertEquals(1, count($paged_results));
Expand All @@ -268,7 +268,7 @@ public function testIntegrationGetAllMethod()
// Get many results (needs to include the created result if self::findCreatedItem === true).
$many_results_per_page = 50;
$many_results = $api->clients()->getAll($fields, true, 0, $many_results_per_page);
usleep(700000);
usleep(150000);

// Make sure we have at least as many results as we requested.
$this->assertLessThanOrEqual($many_results_per_page, count($many_results));
Expand Down
14 changes: 7 additions & 7 deletions tests/API/Management/JobsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function testIntegrationImportUsersJob()
// Get a single, active database connection.
$default_db_name = 'Username-Password-Authentication';
$get_connection_result = $api->connections->getAll( 'auth0', ['id'], true, 0, 1, ['name' => $default_db_name] );
usleep(700000);
usleep(150000);

$conn_id = $get_connection_result[0]['id'];
$import_user_params = [
Expand All @@ -187,15 +187,15 @@ public function testIntegrationImportUsersJob()
];

$import_job_result = $api->jobs()->importUsers(self::$testImportUsersJsonPath, $conn_id, $import_user_params);
usleep(700000);
usleep(150000);

$this->assertEquals( $conn_id, $import_job_result['connection_id'] );
$this->assertEquals( $default_db_name, $import_job_result['connection'] );
$this->assertEquals( '__test_ext_id__', $import_job_result['external_id'] );
$this->assertEquals( 'users_import', $import_job_result['type'] );

$get_job_result = $api->jobs()->get($import_job_result['id']);
usleep(700000);
usleep(150000);

$this->assertEquals( $conn_id, $get_job_result['connection_id'] );
$this->assertEquals( $default_db_name, $get_job_result['connection'] );
Expand Down Expand Up @@ -223,21 +223,21 @@ public function testIntegrationSendEmailVerificationJob()
'password' => uniqid().uniqid().uniqid(),
];
$create_user_result = $api->users->create( $create_user_data );
usleep(700000);
usleep(150000);

$user_id = $create_user_result['user_id'];

$email_job_result = $api->jobs()->sendVerificationEmail($user_id);
usleep(700000);
usleep(150000);

$this->assertEquals( 'verification_email', $email_job_result['type'] );

$get_job_result = $api->jobs()->get($email_job_result['id']);
usleep(700000);
usleep(150000);

$this->assertEquals( 'verification_email', $get_job_result['type'] );

$api->users->delete( $user_id );
usleep(700000);
usleep(150000);
}
}
6 changes: 3 additions & 3 deletions tests/API/Management/LogsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testLogSearchAndGetById()
'fields' => '_id,log_id,date',
'include_fields' => true,
]);
usleep(700000);
usleep(150000);
$this->assertNotEmpty($search_results);
$this->assertNotEmpty($search_results[0]['_id']);
$this->assertNotEmpty($search_results[0]['log_id']);
Expand All @@ -65,7 +65,7 @@ public function testLogSearchAndGetById()

// Test getting a single log result with a valid ID from above.
$one_log = self::$api->get($search_results[0]['log_id']);
usleep(700000);
usleep(150000);
$this->assertNotEmpty($one_log);
$this->assertEquals($search_results[0]['log_id'], $one_log['log_id']);
}
Expand All @@ -90,7 +90,7 @@ public function testLogSearchPagination()
// Include totals to check pagination.
'include_totals' => true,
]);
usleep(700000);
usleep(150000);

$this->assertCount($expected_count, $search_results['logs']);
$this->assertEquals($expected_count, $search_results['length']);
Expand Down
24 changes: 12 additions & 12 deletions tests/API/Management/ResourceServersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function testCreate()
];

$response = self::$api->create(self::$serverIdentifier, $create_data);
usleep(700000);
usleep(150000);

$this->assertNotEmpty($response);
$this->assertNotEmpty($response['id']);
Expand All @@ -111,7 +111,7 @@ public function testCreate()
public function testGet()
{
$response = self::$api->get(self::$serverIdentifier);
usleep(700000);
usleep(150000);
$this->assertNotEmpty($response);
$this->assertEquals(self::$serverIdentifier, $response['identifier']);
}
Expand All @@ -126,7 +126,7 @@ public function testGet()
public function testGetAll()
{
$response = self::$api->getAll();
usleep(700000);
usleep(150000);

// Should have at least the one we created and the management API.
$this->assertGreaterThanOrEqual(2, count($response));
Expand All @@ -144,7 +144,7 @@ public function testGetAll()

// Test pagination.
$response_paged = self::$api->getAll(1, 1);
usleep(700000);
usleep(150000);
$this->assertNotEmpty($response_paged);
$this->assertEquals($response[1]['id'], $response_paged[0]['id']);
}
Expand All @@ -167,7 +167,7 @@ public function testUpdate()
];

$response = self::$api->update(self::$serverIdentifier, $update_data);
usleep(700000);
usleep(150000);

$this->assertEquals($update_data['name'], $response['name']);
$this->assertEquals($update_data['token_lifetime'], $response['token_lifetime']);
Expand All @@ -186,13 +186,13 @@ public function testUpdate()
public function testDelete()
{
$response = self::$api->delete(self::$serverIdentifier);
usleep(700000);
usleep(150000);

// Look for the resource server we just deleted.
$get_server_throws_error = false;
try {
self::$api->get(self::$serverIdentifier);
usleep(700000);
usleep(150000);
} catch (ClientException $e) {
$get_server_throws_error = (404 === $e->getCode());
}
Expand All @@ -214,7 +214,7 @@ public function testExceptions()
$caught_get_no_id_exception = false;
try {
self::$api->get(null);
usleep(700000);
usleep(150000);
} catch (CoreException $e) {
$caught_get_no_id_exception = $this->errorHasString($e, 'Invalid "id" parameter');
}
Expand All @@ -225,7 +225,7 @@ public function testExceptions()
$caught_delete_no_id_exception = false;
try {
self::$api->delete(null);
usleep(700000);
usleep(150000);
} catch (CoreException $e) {
$caught_delete_no_id_exception = $this->errorHasString($e, 'Invalid "id" parameter');
}
Expand All @@ -236,7 +236,7 @@ public function testExceptions()
$caught_update_no_id_exception = false;
try {
self::$api->update(null, []);
usleep(700000);
usleep(150000);
} catch (CoreException $e) {
$caught_update_no_id_exception = $this->errorHasString($e, 'Invalid "id" parameter');
}
Expand All @@ -247,7 +247,7 @@ public function testExceptions()
$caught_create_empty_identifier_param_exception = false;
try {
self::$api->create(null, []);
usleep(700000);
usleep(150000);
} catch (CoreException $e) {
$caught_create_empty_identifier_param_exception = $this->errorHasString($e, 'Invalid "identifier" field');
}
Expand All @@ -257,7 +257,7 @@ public function testExceptions()
$caught_create_invalid_identifier_field_exception = false;
try {
self::$api->create('identifier', ['identifier' => 1234]);
usleep(700000);
usleep(150000);
} catch (CoreException $e) {
$caught_create_invalid_identifier_field_exception = $this->errorHasString($e, 'Invalid "identifier" field');
}
Expand Down
Loading

0 comments on commit 5449a07

Please sign in to comment.