Skip to content

Commit 5a8807a

Browse files
author
Andrea Scuderi
committed
Update tests
1 parent 279f068 commit 5a8807a

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

Tests/BreezeLambdaAPITests/BreezeLambdaAPITests.swift

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,54 +30,58 @@ struct APIConfiguration: APIConfiguring {
3030
}
3131
}
3232

33-
@Suite
33+
@Suite(.serialized)
3434
struct BreezeLambdaAPITests {
3535

3636
let logger = Logger(label: "BreezeHTTPClientServiceTests")
3737

3838
@Test
3939
func test_breezeLambdaAPI_whenValidEnvironment() async throws {
40+
do {
4041
try await testGracefulShutdown { gracefulShutdownTestTrigger in
41-
4242
let (gracefulStream, continuation) = AsyncStream<Void>.makeStream()
43-
4443
try await withThrowingTaskGroup(of: Void.self) { group in
4544
let sut = try await BreezeLambdaAPI<Product>(apiConfig: APIConfiguration())
4645
group.addTask {
47-
try await Task.sleep(nanoseconds: 1_000_000_000)
48-
gracefulShutdownTestTrigger.triggerGracefulShutdown()
49-
}
50-
group.addTask {
51-
try await withGracefulShutdownHandler {
52-
do {
53-
try await sut.run()
54-
print("BreezeLambdaAPIService started successfully")
55-
} catch {
56-
57-
}
46+
try await withGracefulShutdownHandler{
47+
try await sut.run()
5848
} onGracefulShutdown: {
5949
logger.info("On Graceful Shutdown")
6050
continuation.yield()
61-
continuation.finish()
6251
}
6352
}
53+
group.addTask {
54+
try await Task.sleep(nanoseconds: 1_000_000_000)
55+
gracefulShutdownTestTrigger.triggerGracefulShutdown()
56+
}
6457
for await _ in gracefulStream {
58+
continuation.finish()
6559
logger.info("Graceful shutdown stream received")
6660
group.cancelAll()
6761
}
6862
}
6963
}
64+
} catch {
65+
logger.error("Error during test: \(error)")
66+
throw error
67+
}
7068
}
7169

7270
@Test
7371
func test_breezeLambdaAPI_whenInvalidEnvironment() async throws {
7472
await #expect(throws: BreezeLambdaAPIError.self) {
73+
let (errorStream, continuation) = AsyncStream<Error>.makeStream()
7574
try await testGracefulShutdown { gracefulShutdownTestTrigger in
7675
try await withThrowingTaskGroup(of: Void.self) { group in
7776
let sut = try await BreezeLambdaAPI<Product>()
7877
group.addTask {
7978
try await withGracefulShutdownHandler {
80-
try await sut.run()
79+
do {
80+
try await sut.run()
81+
} catch {
82+
continuation.yield(error)
83+
continuation.finish()
84+
}
8185
} onGracefulShutdown: {
8286
logger.info("Performing onGracefulShutdown")
8387
}
@@ -86,7 +90,10 @@ struct BreezeLambdaAPITests {
8690
try await Task.sleep(nanoseconds: 1_000_000_000)
8791
gracefulShutdownTestTrigger.triggerGracefulShutdown()
8892
}
89-
group.cancelAll()
93+
for await _ in errorStream {
94+
logger.info("Error stream received")
95+
group.cancelAll()
96+
}
9097
}
9198
}
9299
}

0 commit comments

Comments
 (0)