Skip to content

Commit 692d45a

Browse files
committed
Reduce the number of iterations to 100,000
Also factor out the number of iterations so future tinkerers have a way to experiment.
1 parent ecdc429 commit 692d45a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Tests/SwiftProtobufTests/Test_AsyncMessageSequence.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,12 @@ final class Test_AsyncMessageSequence: XCTestCase {
202202

203203
// Slow test case found by oss-fuzz: 1 million zero-sized messages
204204
// A similar test with BinaryDelimited is about 4x faster, showing
205-
// that we have some room for improvement here:
205+
// that we have some room for improvement here.
206+
// (Note this currently only tests 100,000 zero-sized messages,
207+
// but the constant below is easy to edit if you want to experiment.)
206208
func testLargeExample() async throws {
207-
let bytes = [UInt8](repeating: 0, count: 1000000)
209+
let messageCount = 100_000
210+
let bytes = [UInt8](repeating: 0, count: messageCount)
208211
let byteStream = asyncByteStream(bytes: bytes)
209212
let decodedStream = byteStream.binaryProtobufDelimitedMessages(
210213
of: SwiftProtoTesting_TestAllTypes.self,
@@ -214,7 +217,7 @@ final class Test_AsyncMessageSequence: XCTestCase {
214217
XCTAssertEqual(message, SwiftProtoTesting_TestAllTypes())
215218
count += 1
216219
}
217-
XCTAssertEqual(count, 1000000)
220+
XCTAssertEqual(count, messageCount)
218221
}
219222

220223
fileprivate func asyncByteStream(bytes: [UInt8]) -> AsyncStream<UInt8> {

Tests/SwiftProtobufTests/Test_BinaryDelimited.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ final class Test_BinaryDelimited: XCTestCase {
148148
// oss-fuzz found this case that runs slowly for AsyncMessageSequence
149149
// Copied here as well for comparison.
150150
func testLargeExample() throws {
151-
let bytes = [UInt8](repeating: 0, count: 1000000)
151+
let messageCount = 100_000
152+
let bytes = [UInt8](repeating: 0, count: messageCount)
152153
let istream = openInputStream(bytes)
153154

154-
for _ in 0..<1000000 {
155+
for _ in 0..<messageCount {
155156
let msg = try BinaryDelimited.parse(
156157
messageType: SwiftProtoTesting_TestAllTypes.self,
157158
from: istream)

0 commit comments

Comments
 (0)