Skip to content

Commit

Permalink
attempt to fix tests on github runners
Browse files Browse the repository at this point in the history
  • Loading branch information
ypopovych committed Mar 18, 2024
1 parent 4bb3729 commit 72e946b
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions Tests/EventsExporter/Persistence/FileWriterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,27 @@ class FileWriterTests: XCTestCase {
)
)

let ioInterruptionQueue = DispatchQueue(label: "com.datadohq.file-writer-random-io")
let ioInterruptionQueue = DispatchQueue(
label: "com.datadohq.file-writer-random-io",
target: .global(qos: writer.queue.qos.qosClass)
)

func randomlyInterruptIO(for file: File) {
ioInterruptionQueue.async { try? file.makeReadonly() }
ioInterruptionQueue.async { try? file.makeReadWrite() }
func randomlyInterruptIO(for file: File?) {
ioInterruptionQueue.async {
try? file?.makeReadonly()
usleep(300)
try? file?.makeReadWrite()
}
}

struct Foo: Codable {
var foo = "bar"
}

writer.writeSync(value: Foo())

// Write 299 more of `Foo`s and interrupt writes randomly
(1..<300).forEach { _ in
// Write 300 of `Foo`s and interrupt writes randomly
try (0..<300).forEach { _ in
writer.write(value: Foo())
randomlyInterruptIO(for: try! temporaryDirectory.files().first!)
randomlyInterruptIO(for: try temporaryDirectory.files().first)
}

ioInterruptionQueue.sync {}
Expand All @@ -127,7 +131,7 @@ class FileWriterTests: XCTestCase {
// Assert that data written is not malformed
let writtenData = try jsonDecoder.decode([Foo].self, from: "[".utf8Data + fileData + "]".utf8Data)
// Assert that some (including all) `Foo`s were written
XCTAssertGreaterThan(writtenData.count, 1)
XCTAssertGreaterThan(writtenData.count, 0)
XCTAssertLessThanOrEqual(writtenData.count, 300)
}

Expand Down

0 comments on commit 72e946b

Please sign in to comment.