From cbbd6e05d65015d26f90e001cabcc5857c9b2134 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Tue, 1 Mar 2016 11:08:27 +1100 Subject: Failed postgres tests if cannot connect to host/db Otherwise the tests will just wait indefinitely --- .../PostgresKit/Tests/PGPostgresIntegrationTestCase.m | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Frameworks') diff --git a/Frameworks/PostgresKit/Tests/PGPostgresIntegrationTestCase.m b/Frameworks/PostgresKit/Tests/PGPostgresIntegrationTestCase.m index 96de8a40..231e1bfa 100644 --- a/Frameworks/PostgresKit/Tests/PGPostgresIntegrationTestCase.m +++ b/Frameworks/PostgresKit/Tests/PGPostgresIntegrationTestCase.m @@ -35,6 +35,8 @@ static NSString *PGTestDatabasePassword = @"pgkit"; static NSUInteger PGTestDatabasePort = 5432; +static double PGTestConnectionTimeout = 0.2; + @interface PGPostgresIntegrationTestCase () - (void)_establishConnection; @@ -72,8 +74,20 @@ static NSUInteger PGTestDatabasePort = 5432; exit(1); } + NSDate *startDate = [NSDate date]; + do { sleep(0.1); + + if([[NSDate date] timeIntervalSinceDate:startDate] > PGTestConnectionTimeout) { + XCTFail(@"Failed to connect to database after %f seconds. Host:%@ Database:%@ User:%@ Password:%@", + PGTestConnectionTimeout, + PGTestDatabaseHost, + PGTestDatabaseName, + PGTestDatabaseUser, + PGTestDatabasePassword); + exit(1); + } } while (![_connection isConnected]); } -- cgit v1.2.3