Skip to content

Commit

Permalink
test: add timeout case
Browse files Browse the repository at this point in the history
  • Loading branch information
lovetodream committed Apr 22, 2024
1 parent 002ceeb commit 4cd47fb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
cd swift-format
git checkout "tags/$VERSION"
swift build -c release
export SWIFTFORMAT_BIN=$(pwd)/.build/release/swift-format
cd "${GITHUB_WORKSPACE}"
- name: Run soundness
run: |
export SWIFTFORMAT_BIN=$(pwd)/../swift-format/.build/release/swift-format
scripts/soundness.sh
exit $(git status --porcelain | wc -l)
Expand Down
38 changes: 38 additions & 0 deletions Tests/LoggingLokiTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,44 @@ final class IntegrationTests: XCTestCase {
try await runHappyPath(LokiJSONTransformer())
}

func testTimeout() async throws {
try await withThrowingDiscardingTaskGroup { group in
let clock = TestClock()
let transport = InspectableTransport()
let processor = LokiLogProcessor(
configuration: .init(
lokiURL: "http://localhost:420420",
maxBatchTimeInterval: .seconds(10)),
transport: transport,
transformer: BadRequestTransformer(),
clock: clock
)
var sleepCalls = clock.sleepCalls.makeAsyncIterator()
group.addTask {
try await processor.run()
}
let handler = LokiLogHandler(
label: "com.timozacherl.swift-log-loki-tests", processor: processor)
logLine(handler: handler)
await sleepCalls.next()

// move forward in time until max batch time interval is exceeded
clock.advance(by: .seconds(5)) // tick
await sleepCalls.next()
clock.advance(by: .seconds(5)) // tick
await sleepCalls.next()

clock.advance(by: .seconds(30))
await sleepCalls.next() // export
XCTAssertEqual(transport.transported.load(ordering: .relaxed), 0)
XCTAssertEqual(transport.errored.load(ordering: .relaxed), 1)
let errors = transport.errors.withLockedValue { $0 }
XCTAssertTrue(errors.first is CancellationError)

group.cancelAll()
}
}

func testBadRequest() async throws {
try await withThrowingDiscardingTaskGroup { group in
let clock = TestClock()
Expand Down

0 comments on commit 4cd47fb

Please sign in to comment.