Skip to content

Commit ac96939

Browse files
committed
fixed issue again
1 parent 6ddce35 commit ac96939

5 files changed

Lines changed: 61 additions & 35 deletions

File tree

.github/workflows/swift.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,27 @@ jobs:
5252
export PATH="/opt/swift/usr/bin:${PATH}"
5353
- uses: actions/checkout@v2
5454

55+
- name: Install PostgreSQL Client Tools
56+
run: |
57+
sudo apt-get update
58+
sudo apt-get install -y postgresql-client
59+
5560
- name: Setup PostgreSQL Database Schema
5661
run: |
5762
# Wait for PostgreSQL service to be ready
5863
until pg_isready -h localhost -p 5432 -U fuzzilli; do
5964
echo "Waiting for PostgreSQL service to be ready..."
6065
sleep 2
6166
done
62-
67+
6368
# Initialize the database schema
6469
PGPASSWORD=fuzzilli123 psql -h localhost -p 5432 -U fuzzilli -d fuzzilli -f postgres-init.sql
65-
70+
6671
# Verify the schema was created
6772
PGPASSWORD=fuzzilli123 psql -h localhost -p 5432 -U fuzzilli -d fuzzilli -c "
68-
SELECT table_name
69-
FROM information_schema.tables
70-
WHERE table_schema = 'public'
73+
SELECT table_name
74+
FROM information_schema.tables
75+
WHERE table_schema = 'public'
7176
ORDER BY table_name;
7277
"
7378

Tests/FuzzilliTests/PostgreSQLCorpusIntegrationTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ final class PostgreSQLCorpusIntegrationTests: XCTestCase {
66

77
func testPostgreSQLCorpusCLIIntegration() {
88
// Test that PostgreSQL corpus can be created with proper configuration
9-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
9+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
1010
let fuzzerInstanceId = "test-fuzzer-123"
1111

1212
let corpus = PostgreSQLCorpus(
@@ -24,7 +24,7 @@ final class PostgreSQLCorpusIntegrationTests: XCTestCase {
2424

2525
func testPostgreSQLCorpusConfiguration() {
2626
// Test that PostgreSQL corpus accepts the same configuration as BasicCorpus
27-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
27+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
2828
let fuzzerInstanceId = "test-fuzzer-456"
2929

3030
let corpus = PostgreSQLCorpus(
@@ -49,7 +49,7 @@ final class PostgreSQLCorpusIntegrationTests: XCTestCase {
4949

5050
func testPostgreSQLCorpusProtocolConformance() {
5151
// Test that PostgreSQLCorpus properly implements the Corpus protocol
52-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
52+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
5353
let fuzzerInstanceId = "test-fuzzer-789"
5454

5555
let corpus: Corpus = PostgreSQLCorpus(
@@ -85,7 +85,7 @@ final class PostgreSQLCorpusIntegrationTests: XCTestCase {
8585

8686
func testPostgreSQLCorpusWithDifferentSizes() {
8787
// Test PostgreSQL corpus with different size configurations
88-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
88+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
8989
let fuzzerInstanceId = "test-fuzzer-sizes"
9090

9191
// Test with small sizes
@@ -115,7 +115,7 @@ final class PostgreSQLCorpusIntegrationTests: XCTestCase {
115115

116116
func testPostgreSQLCorpusStatistics() {
117117
// Test that statistics are properly tracked
118-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
118+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
119119
let fuzzerInstanceId = "test-fuzzer-stats"
120120

121121
let corpus = PostgreSQLCorpus(

Tests/FuzzilliTests/PostgreSQLCorpusTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Foundation
55
final class PostgreSQLCorpusTests: XCTestCase {
66

77
func testPostgreSQLCorpusInitialization() {
8-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
8+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
99
let corpus = PostgreSQLCorpus(
1010
minSize: 10,
1111
maxSize: 100,
@@ -20,7 +20,7 @@ final class PostgreSQLCorpusTests: XCTestCase {
2020
}
2121

2222
func testPostgreSQLCorpusAddProgram() {
23-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
23+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
2424

2525
// Create corpus
2626
let corpus = PostgreSQLCorpus(
@@ -43,7 +43,7 @@ final class PostgreSQLCorpusTests: XCTestCase {
4343
}
4444

4545
func testPostgreSQLCorpusRandomElementAccess() {
46-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
46+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
4747
let corpus = PostgreSQLCorpus(
4848
minSize: 10,
4949
maxSize: 100,
@@ -62,7 +62,7 @@ final class PostgreSQLCorpusTests: XCTestCase {
6262
}
6363

6464
func testPostgreSQLCorpusAllPrograms() {
65-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
65+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
6666
let corpus = PostgreSQLCorpus(
6767
minSize: 10,
6868
maxSize: 100,
@@ -78,7 +78,7 @@ final class PostgreSQLCorpusTests: XCTestCase {
7878
}
7979

8080
func testPostgreSQLCorpusStateExportImport() throws {
81-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
81+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
8282
let corpus = PostgreSQLCorpus(
8383
minSize: 10,
8484
maxSize: 100,
@@ -106,7 +106,7 @@ final class PostgreSQLCorpusTests: XCTestCase {
106106
}
107107

108108
func testPostgreSQLCorpusDuplicateProgramHandling() {
109-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
109+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
110110
let corpus = PostgreSQLCorpus(
111111
minSize: 10,
112112
maxSize: 100,
@@ -121,7 +121,7 @@ final class PostgreSQLCorpusTests: XCTestCase {
121121
}
122122

123123
func testPostgreSQLCorpusStatistics() {
124-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
124+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
125125
let corpus = PostgreSQLCorpus(
126126
minSize: 10,
127127
maxSize: 100,
@@ -140,7 +140,7 @@ final class PostgreSQLCorpusTests: XCTestCase {
140140
}
141141

142142
func testPostgreSQLCorpusWithDifferentAspects() {
143-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
143+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
144144
let corpus = PostgreSQLCorpus(
145145
minSize: 10,
146146
maxSize: 100,
@@ -171,7 +171,7 @@ final class PostgreSQLCorpusTests: XCTestCase {
171171
}
172172

173173
func testPostgreSQLCorpusInterestingProgramTracking() {
174-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
174+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
175175
let corpus = PostgreSQLCorpus(
176176
minSize: 1,
177177
maxSize: 10,

Tests/FuzzilliTests/PostgreSQLStorageTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class PostgreSQLStorageTests: XCTestCase {
1717
}
1818

1919
func testFuzzerRegistration() async throws {
20-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
20+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
2121
let storage = PostgreSQLStorage(databasePool: databasePool)
2222

2323
// Test fuzzer registration (this would fail without actual database)
@@ -37,7 +37,7 @@ final class PostgreSQLStorageTests: XCTestCase {
3737
}
3838

3939
func testProgramStorage() async throws {
40-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
40+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
4141
let storage = PostgreSQLStorage(databasePool: databasePool)
4242

4343
// Create execution metadata
@@ -64,7 +64,7 @@ final class PostgreSQLStorageTests: XCTestCase {
6464
}
6565

6666
func testExecutionStorage() async throws {
67-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
67+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
6868
let storage = PostgreSQLStorage(databasePool: databasePool)
6969

7070
// Test execution storage interface
@@ -89,7 +89,7 @@ final class PostgreSQLStorageTests: XCTestCase {
8989
}
9090

9191
func testCrashStorage() async throws {
92-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
92+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
9393
let storage = PostgreSQLStorage(databasePool: databasePool)
9494

9595
// Test crash storage interface
@@ -113,7 +113,7 @@ final class PostgreSQLStorageTests: XCTestCase {
113113
}
114114

115115
func testProgramRetrieval() async throws {
116-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
116+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
117117
let storage = PostgreSQLStorage(databasePool: databasePool)
118118

119119
// Test program retrieval (this would fail without actual database)
@@ -128,7 +128,7 @@ final class PostgreSQLStorageTests: XCTestCase {
128128
}
129129

130130
func testMetadataRetrieval() async throws {
131-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
131+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
132132
let storage = PostgreSQLStorage(databasePool: databasePool)
133133

134134
// Test metadata retrieval
@@ -143,7 +143,7 @@ final class PostgreSQLStorageTests: XCTestCase {
143143
}
144144

145145
func testExecutionHistoryRetrieval() async throws {
146-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
146+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
147147
let storage = PostgreSQLStorage(databasePool: databasePool)
148148

149149
// Test execution history retrieval
@@ -158,7 +158,7 @@ final class PostgreSQLStorageTests: XCTestCase {
158158
}
159159

160160
func testRecentProgramsRetrieval() async throws {
161-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
161+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
162162
let storage = PostgreSQLStorage(databasePool: databasePool)
163163

164164
// Test recent programs retrieval
@@ -173,7 +173,7 @@ final class PostgreSQLStorageTests: XCTestCase {
173173
}
174174

175175
func testMetadataUpdate() async throws {
176-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
176+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
177177
let storage = PostgreSQLStorage(databasePool: databasePool)
178178

179179
// Create execution metadata
@@ -193,7 +193,7 @@ final class PostgreSQLStorageTests: XCTestCase {
193193
}
194194

195195
func testStorageStatistics() async throws {
196-
let databasePool = DatabasePool(connectionString: "PostgreSQLTestUtils.getConnectionString()")
196+
let databasePool = DatabasePool(connectionString: PostgreSQLTestUtils.getConnectionString())
197197
let storage = PostgreSQLStorage(databasePool: databasePool)
198198

199199
// Test storage statistics

Tests/FuzzilliTests/PostgreSQLTestUtils.swift

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,33 @@ public class PostgreSQLTestUtils {
1212

1313
/// Check if PostgreSQL is available for testing
1414
public static func isPostgreSQLAvailable() -> Bool {
15-
// In CI environments, PostgreSQL is always available on Linux runners
16-
if ProcessInfo.processInfo.environment["DATABASE_URL"] != nil {
17-
return true
15+
// Try to create a database pool and test the connection
16+
do {
17+
let connectionString = getConnectionString()
18+
let databasePool = DatabasePool(connectionString: connectionString)
19+
20+
// Try to initialize the pool
21+
let semaphore = DispatchSemaphore(value: 0)
22+
var isAvailable = false
23+
24+
Task {
25+
do {
26+
try await databasePool.initialize()
27+
let connected = try await databasePool.testConnection()
28+
isAvailable = connected
29+
await databasePool.shutdown()
30+
} catch {
31+
isAvailable = false
32+
}
33+
semaphore.signal()
34+
}
35+
36+
// Wait for the async operation to complete (with timeout)
37+
let result = semaphore.wait(timeout: .now() + 5.0)
38+
return result == .success && isAvailable
39+
40+
} catch {
41+
return false
1842
}
19-
20-
// For local testing, assume it's available
21-
return true
2243
}
2344
}

0 commit comments

Comments
 (0)