Skip to content

Commit a4f69b6

Browse files
committed
wip
1 parent 5bbe0d8 commit a4f69b6

File tree

9 files changed

+80
-47
lines changed

9 files changed

+80
-47
lines changed

.devcontainer/devcontainer.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
{
22
"name": "spi-base",
33
"build": { "dockerfile": "Dockerfile" },
4-
"extensions": [
5-
"sswg.swift-lang"
6-
],
7-
"settings": {
8-
"lldb.library": "/usr/lib/liblldb.so"
4+
"forwardPorts": [8080],
5+
"customizations": {
6+
"vscode": {
7+
"extensions": [
8+
"sswg.swift-lang"
9+
],
10+
"settings": {
11+
"lldb.library": "/usr/lib/liblldb.so"
12+
}
13+
}
914
},
10-
"forwardPorts": [8080]
15+
"runArgs": [
16+
"--network=spi_test"
17+
]
1118
}

.github/workflows/ci.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
COLLECTION_SIGNING_PRIVATE_KEY: ${{ secrets.COLLECTION_SIGNING_PRIVATE_KEY }}
4646
DATABASEPOOL_SIZE: 8
4747
services:
48-
db-0:
48+
spi_test_0:
4949
image: postgres:16-alpine
5050
env:
5151
POSTGRES_DB: spi_test
@@ -56,7 +56,7 @@ jobs:
5656
--health-interval 10s
5757
--health-timeout 5s
5858
--health-retries 5
59-
db-1:
59+
spi_test_1:
6060
image: postgres:16-alpine
6161
env:
6262
POSTGRES_DB: spi_test
@@ -67,7 +67,7 @@ jobs:
6767
--health-interval 10s
6868
--health-timeout 5s
6969
--health-retries 5
70-
db-2:
70+
spi_test_2:
7171
image: postgres:16-alpine
7272
env:
7373
POSTGRES_DB: spi_test
@@ -78,7 +78,7 @@ jobs:
7878
--health-interval 10s
7979
--health-timeout 5s
8080
--health-retries 5
81-
db-3:
81+
spi_test_3:
8282
image: postgres:16-alpine
8383
env:
8484
POSTGRES_DB: spi_test
@@ -89,7 +89,7 @@ jobs:
8989
--health-interval 10s
9090
--health-timeout 5s
9191
--health-retries 5
92-
db-4:
92+
spi_test_4:
9393
image: postgres:16-alpine
9494
env:
9595
POSTGRES_DB: spi_test
@@ -100,7 +100,7 @@ jobs:
100100
--health-interval 10s
101101
--health-timeout 5s
102102
--health-retries 5
103-
db-5:
103+
spi_test_5:
104104
image: postgres:16-alpine
105105
env:
106106
POSTGRES_DB: spi_test
@@ -111,7 +111,7 @@ jobs:
111111
--health-interval 10s
112112
--health-timeout 5s
113113
--health-retries 5
114-
db-6:
114+
spi_test_6:
115115
image: postgres:16-alpine
116116
env:
117117
POSTGRES_DB: spi_test
@@ -122,7 +122,7 @@ jobs:
122122
--health-interval 10s
123123
--health-timeout 5s
124124
--health-retries 5
125-
db-7:
125+
spi_test_7:
126126
image: postgres:16-alpine
127127
env:
128128
POSTGRES_DB: spi_test

Tests/AppTests/AllTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
@testable import App
1616

1717
import Dependencies
18+
import SnapshotTesting
1819
import Testing
1920

2021

2122
@Suite(
2223
.setupDatabasePool,
2324
.dependency(\.date.now, .t0),
24-
.dependency(\.metricsSystem, .mock)
25+
.dependency(\.metricsSystem, .mock),
26+
.snapshots(record: .failed)
2527
) struct AllTests { }
2628

2729

Tests/AppTests/Helpers/DatabasePool.swift

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ actor DatabasePool {
9494
}
9595

9696
func tearDown() async throws {
97-
if isRunningInCI() {
98-
// Let the CI system deal with the databases, there's nothing we can or should do here.
99-
} else {
100-
try await tearDown(databases: runningDatabases())
101-
}
97+
try await tearDown(databases: runningDatabases())
10298
}
10399

104100
func tearDown(databases: any Collection<Database>) async throws {
@@ -142,20 +138,20 @@ actor DatabasePool {
142138
}
143139

144140
private func retainDatabase() async throws -> Database {
145-
let start = Date()
146-
print("ℹ️ \(#function) start")
147-
defer { print("ℹ️ \(#function) end", Date().timeIntervalSince(start)) }
141+
// let start = Date()
142+
// print("ℹ️ \(#function) start")
143+
// defer { print("ℹ️ \(#function) end", Date().timeIntervalSince(start)) }
148144
var database = availableDatabases.randomElement()
149-
var retry = 0
145+
// var retry = 0
150146
while database == nil {
151-
defer { retry += 1 }
152-
if retry > 0 && retry % 50 == 0 {
153-
print("ℹ️ \(#function) available databases: \(availableDatabases.count) retry \(retry)")
154-
}
155-
if retry >= 1000 {
156-
throw "Retry count exceeded"
157-
}
158-
try await Task.sleep(for: .milliseconds(100))
147+
// defer { retry += 1 }
148+
// if retry > 0 && retry % 50 == 0 {
149+
// print("ℹ️ \(#function) available databases: \(availableDatabases.count) retry \(retry)")
150+
// }
151+
// if retry >= 1000 {
152+
// throw "Retry count exceeded"
153+
// }
154+
try await Task.sleep(for: .milliseconds(10))
159155
database = availableDatabases.randomElement()
160156
}
161157
guard let database else { fatalError("database cannot be nil here") }
@@ -199,7 +195,7 @@ extension DatabasePool.Database {
199195
// This is safeguard against accidental inheritance of setup in QueryPerformanceTests
200196
// and to ensure the database resetting cannot impact any other network hosts.
201197
if isRunningInCI() {
202-
self.host = "db-\(index)"
198+
self.host = "spi_test_\(index)"
203199
self.port = 5432
204200
} else {
205201
self.host = Environment.get("DATABASE_HOST")!
@@ -223,7 +219,7 @@ extension DatabasePool.Database {
223219
print("ℹ️ \(#function) start")
224220
defer { print("ℹ️ \(#function) end", Date().timeIntervalSince(start)) }
225221
do {
226-
try await _withDatabase("postgres", details: connectionDetails, timeout: .seconds(5)) { // Connect to `postgres` db in order to reset the test db
222+
try await _withDatabase("postgres", details: connectionDetails, timeout: .seconds(10)) { // Connect to `postgres` db in order to reset the test db
227223
let databaseName = Environment.get("DATABASE_NAME")!
228224
try await $0.query(PostgresQuery(unsafeSQL: "DROP DATABASE IF EXISTS \(databaseName) WITH (FORCE)"))
229225
try await $0.query(PostgresQuery(unsafeSQL: "CREATE DATABASE \(databaseName)"))
@@ -249,7 +245,7 @@ extension DatabasePool.Database {
249245
let original = Environment.get("DATABASE_NAME")!
250246
let snapshot = original + "_snapshot"
251247
do {
252-
try await _withDatabase("postgres", details: connectionDetails, timeout: .seconds(5)) { client in
248+
try await _withDatabase("postgres", details: connectionDetails, timeout: .seconds(10)) { client in
253249
try await client.query(PostgresQuery(unsafeSQL: "DROP DATABASE IF EXISTS \(snapshot) WITH (FORCE)"))
254250
try await client.query(PostgresQuery(unsafeSQL: "CREATE DATABASE \(snapshot) TEMPLATE \(original)"))
255251
}
@@ -264,7 +260,7 @@ extension DatabasePool.Database {
264260
let snapshot = original + "_snapshot"
265261
// delete db and re-create from snapshot
266262
do {
267-
try await _withDatabase("postgres", details: details, timeout: .seconds(1)) { client in
263+
try await _withDatabase("postgres", details: details, timeout: .seconds(10)) { client in
268264
try await client.query(PostgresQuery(unsafeSQL: "DROP DATABASE IF EXISTS \(original) WITH (FORCE)"))
269265
try await client.query(PostgresQuery(unsafeSQL: "CREATE DATABASE \(original) TEMPLATE \(snapshot)"))
270266
}
@@ -312,11 +308,19 @@ private func _withDatabase(_ databaseName: String,
312308

313309
extension Environment {
314310
static var databasePoolSize: Int {
315-
Environment.get("DATABASEPOOL_SIZE").flatMap(Int.init) ?? 4
311+
if isRunningInCI() {
312+
8
313+
} else {
314+
Environment.get("DATABASEPOOL_SIZE").flatMap(Int.init) ?? 4
315+
}
316316
}
317317

318318
static var databasePoolTearDown: Bool {
319-
Environment.get("DATABASEPOOL_TEARDOWN").flatMap(\.asBool) ?? true
319+
if isRunningInCI() {
320+
false
321+
} else {
322+
Environment.get("DATABASEPOOL_TEARDOWN").flatMap(\.asBool) ?? true
323+
}
320324
}
321325
}
322326

Tests/AppTests/Helpers/ShellOutCommand+ext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extension ShellOutCommand {
2626
"--tmpfs", "/pgdata:rw,noexec,nosuid,size=1024m",
2727
"-p", "\(port):5432",
2828
"-d",
29-
"postgres:16-alpine"
29+
"postgres:13-alpine"
3030
])
3131
}
3232

Tests/AppTests/__Snapshots__/AnalyzerTests/dumpPackage_format.linux.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
"upperBound" : "510.0.0"
2222
}
2323
]
24-
}
24+
},
25+
"traits" : [
26+
{
27+
"name" : "default"
28+
}
29+
]
2530
}
2631
]
2732
}
@@ -204,5 +209,8 @@
204209
],
205210
"toolsVersion" : {
206211
"_version" : "5.9.0"
207-
}
212+
},
213+
"traits" : [
214+
215+
]
208216
}

Tests/AppTests/__Snapshots__/AnalyzerTests/dumpPackage_format.macos.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
"upperBound" : "510.0.0"
2222
}
2323
]
24-
}
24+
},
25+
"traits" : [
26+
{
27+
"name" : "default"
28+
}
29+
]
2530
}
2631
]
2732
}
@@ -210,5 +215,8 @@
210215
],
211216
"toolsVersion" : {
212217
"_version" : "5.9.0"
213-
}
218+
},
219+
"traits" : [
220+
221+
]
214222
}

scripts/start-test-dbs.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#!/usr/bin/env bash
22

3-
for port in {6000..6007}; do
3+
docker network create -d bridge spi_test
4+
5+
for port in {0..7}; do
46
docker run --name "spi_test_$port" \
57
-e POSTGRES_DB=spi_test \
68
-e POSTGRES_USER=spi_test \
79
-e POSTGRES_PASSWORD=xxx \
810
-e PGDATA=/pgdata \
911
--tmpfs /pgdata:rw,noexec,nosuid,size=1024m \
10-
-p "$port":5432 \
12+
--network spi_test \
1113
-d \
12-
postgres:16-alpine
14+
postgres:13-alpine
1315
done

scripts/stop-test-dbs.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3-
for c in $(docker ps --format "{{.Names}}" | grep spi_test_); do
3+
for c in $(docker ps --all --format "{{.Names}}" | grep spi_test_); do
44
docker rm -f "$c"
55
done
6+
7+
docker network rm spi_test

0 commit comments

Comments
 (0)