Skip to content

Commit b02933d

Browse files
Merge pull request #3307 from SwiftPackageIndex/fix-collection-tests
Update base image, tests
2 parents e5a7249 + 40b90d5 commit b02933d

File tree

12 files changed

+72
-17
lines changed

12 files changed

+72
-17
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM registry.gitlab.com/finestructure/spi-base:1.0.1
1+
FROM registry.gitlab.com/finestructure/spi-base:1.0.2
22

33
# Install SPM build dependencies
44
RUN apt-get update && apt-get install -y curl git make unzip \

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
name: Test
2626
runs-on: ubuntu-latest
2727
container:
28-
image: registry.gitlab.com/finestructure/spi-base:1.0.1
28+
image: registry.gitlab.com/finestructure/spi-base:1.0.2
2929
options: --privileged
3030
services:
3131
postgres:

.github/workflows/query-performance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
runs-on: ubuntu-latest
2525
continue-on-error: true
2626
container:
27-
image: registry.gitlab.com/finestructure/spi-base:1.0.1
27+
image: registry.gitlab.com/finestructure/spi-base:1.0.2
2828
steps:
2929
- name: Checkout code
3030
uses: actions/checkout@v4

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# ================================
1919
# Build image
2020
# ================================
21-
FROM registry.gitlab.com/finestructure/spi-base:1.0.1 as build
21+
FROM registry.gitlab.com/finestructure/spi-base:1.0.2 as build
2222

2323
# Set up a build area
2424
WORKDIR /build
@@ -61,7 +61,7 @@ RUN [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w
6161
# ================================
6262
# Run image
6363
# ================================
64-
FROM registry.gitlab.com/finestructure/spi-base:1.0.1
64+
FROM registry.gitlab.com/finestructure/spi-base:1.0.2
6565

6666
# NB sas 2022-09-23: We're not using a dedicated `vapor` user to run the executable, because it
6767
# makes managing the data in the checkouts volume difficult. See

LOCAL_DEVELOPMENT_SETUP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ The trickiest part of this is to ensure the test or app container can connect to
218218
So, in order to run the tests in a Linux container run:
219219

220220
```
221-
docker run --rm -v "$PWD":/host -w /host --add-host=host.docker.internal:host-gateway registry.gitlab.com/finestructure/spi-base:1.0.1 swift test
221+
docker run --rm -v "$PWD":/host -w /host --add-host=host.docker.internal:host-gateway registry.gitlab.com/finestructure/spi-base:1.0.2 swift test
222222
```
223223

224224
Make sure you use the most recent `spi-base` image. You can find the latest image name in the `test-docker` target, which also provides a convenient way to run all all tests in a docker container.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ test-docker:
6868
@# run tests inside a docker container
6969
docker run --rm -v "$(PWD)":/host -w /host \
7070
--add-host=host.docker.internal:host-gateway \
71-
registry.gitlab.com/finestructure/spi-base:1.0.1 \
71+
registry.gitlab.com/finestructure/spi-base:1.0.2 \
7272
make test
7373

7474
test-e2e: db-reset reconcile ingest analyze

Tests/AppTests/ApiTests.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,12 @@ class ApiTests: AppTestCase {
414414
// setup
415415
Current.builderToken = { "secr3t" }
416416
let p = try savePackage(on: app.db, "1")
417-
let originalPackageUpdate = p.updatedAt
417+
let originalPackageUpdate = try XCTUnwrap(p.updatedAt)
418418
let v = try Version(package: p, latest: .defaultBranch)
419419
try await v.save(on: app.db)
420420
let versionId = try v.requireID()
421+
// Sleep for 1ms to ensure we can detect a difference between update times.
422+
try await Task.sleep(nanoseconds: UInt64(1e6))
421423

422424
// MUT
423425
let dto: API.PostBuildReportDTO = .init(
@@ -448,7 +450,22 @@ class ApiTests: AppTestCase {
448450
afterResponse: { res async throws in
449451
// validation
450452
let p = try await XCTUnwrapAsync(await Package.find(p.id, on: app.db))
451-
XCTAssertEqual(p.updatedAt, originalPackageUpdate)
453+
#if os(Linux)
454+
if p.updatedAt == originalPackageUpdate {
455+
logWarning()
456+
// When this triggers, remove Task.sleep above and the validtion below until // TEMPORARY - END
457+
// and replace with original assert:
458+
// XCTAssertEqual(p.updatedAt, originalPackageUpdate)
459+
}
460+
#endif
461+
let updatedAt = try XCTUnwrap(p.updatedAt)
462+
// Comaring the dates directly fails due to tiny rounding differences with the new swift-foundation types on Linux
463+
// E.g.
464+
// 1724071056.5824609
465+
// 1724071056.5824614
466+
// By testing only to accuracy 10e-5 and delaying by 10e-3 we ensure we properly detect if the value was changed.
467+
XCTAssertEqual(updatedAt.timeIntervalSince1970, originalPackageUpdate.timeIntervalSince1970, accuracy: 10e-5)
468+
// TEMPORARY - END
452469
})
453470
}
454471

@@ -1086,3 +1103,10 @@ extension String {
10861103
return try s.generateToken(for: "", contact: "", tier: tier)
10871104
}
10881105
}
1106+
1107+
1108+
private func logWarning(filePath: StaticString = #filePath,
1109+
lineNumber: UInt = #line,
1110+
testName: String = #function) {
1111+
print("::error file=\(filePath),line=\(lineNumber),title=\(testName)::Direct comparison of updatedAt is working again, replace comparison with the Task.sleep delay.")
1112+
}

Tests/AppTests/HomeIndexModelTests.swift

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,55 @@ class HomeIndexModelTests: AppTestCase {
3333
reference: .tag(.init(1, 2, 3))).save(on: app.db)
3434
try await RecentPackage.refresh(on: app.db)
3535
try await RecentRelease.refresh(on: app.db)
36+
// Sleep for 1ms to ensure we can detect a difference between update times.
37+
try await Task.sleep(nanoseconds: UInt64(1e6))
3638

3739
// MUT
3840
let m = try await HomeIndex.Model.query(database: app.db)
3941

4042
// validate
4143
let createdAt = try XCTUnwrap(pkg.createdAt)
42-
XCTAssertEqual(m.recentPackages, [
44+
#if os(Linux)
45+
if m.recentPackages == [
4346
.init(
4447
date: createdAt,
4548
link: .init(label: "Package", url: "/foo/1")
4649
)
47-
])
50+
] {
51+
logWarning()
52+
// When this triggers, remove Task.sleep above and the validtion below until // TEMPORARY - END
53+
// and replace with original assert:
54+
// XCTAssertEqual(m.recentPackages, [
55+
// .init(
56+
// date: createdAt,
57+
// link: .init(label: "Package", url: "/foo/1")
58+
// )
59+
// ])
60+
}
61+
#endif
62+
XCTAssertEqual(m.recentPackages.count, 1)
63+
let recent = try XCTUnwrap(m.recentPackages.first)
64+
// Comaring the dates directly fails due to tiny rounding differences with the new swift-foundation types on Linux
65+
// E.g.
66+
// 1724071056.5824609
67+
// 1724071056.5824614
68+
// By testing only to accuracy 10e-5 and delaying by 10e-3 we ensure we properly detect if the value was changed.
69+
XCTAssertEqual(recent.date.timeIntervalSince1970, createdAt.timeIntervalSince1970, accuracy: 10e-5)
70+
XCTAssertEqual(recent.link, .init(label: "Package", url: "/foo/1"))
4871
XCTAssertEqual(m.recentReleases, [
4972
.init(packageName: "Package",
5073
version: "1.2.3",
5174
date: "\(date: Date(timeIntervalSince1970: 0), relativeTo: Current.date())",
5275
url: "/foo/1"),
5376
])
77+
// TEMPORARY - END
5478
}
5579

5680
}
81+
82+
83+
private func logWarning(filePath: StaticString = #filePath,
84+
lineNumber: UInt = #line,
85+
testName: String = #function) {
86+
print("::error file=\(filePath),line=\(lineNumber),title=\(testName)::Direct comparison of recentPackages is working again, replace by-property comparison with the Task.sleep delay.")
87+
}

Tests/AppTests/__Snapshots__/PackageCollectionControllerTests/test_owner_request.1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
},
5252
"signer" : {
5353
"commonName" : "Swift Package Index",
54-
"organizationalUnitName" : "Swift Package Index",
5554
"organizationName" : "Swift Package Index",
55+
"organizationalUnitName" : "Swift Package Index",
5656
"type" : "ADP"
5757
},
5858
"verifiedCompatibility" : [

Tests/AppTests/__Snapshots__/PackageCollectionTests/test_generate_for_owner.1.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
},
6060
"signer" : {
6161
"commonName" : "Swift Package Index",
62-
"organizationalUnitName" : "Swift Package Index",
6362
"organizationName" : "Swift Package Index",
63+
"organizationalUnitName" : "Swift Package Index",
6464
"type" : "ADP"
6565
},
6666
"verifiedCompatibility" : [
@@ -123,8 +123,8 @@
123123
},
124124
"signer" : {
125125
"commonName" : "Swift Package Index",
126-
"organizationalUnitName" : "Swift Package Index",
127126
"organizationName" : "Swift Package Index",
127+
"organizationalUnitName" : "Swift Package Index",
128128
"type" : "ADP"
129129
},
130130
"verifiedCompatibility" : [

0 commit comments

Comments
 (0)