Skip to content

Commit 25070ec

Browse files
artemredkinweissi
authored andcommitted
fix race in backpressure tests (#46)
* fix race in backpressure tests
1 parent b019e08 commit 25070ec

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Tests/NIOHTTPClientTests/SwiftNIOHTTPTests.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import Foundation
1616
import NIO
17+
import NIOConcurrencyHelpers
1718
import NIOFoundationCompat
1819
@testable import NIOHTTP1
1920
@testable import NIOHTTPClient
@@ -405,15 +406,25 @@ class SwiftHTTPTests: XCTestCase {
405406
class BackpressureTestDelegate: HTTPClientResponseDelegate {
406407
typealias Response = Void
407408

408-
var reads = 0
409+
var _reads = 0
410+
let lock: Lock
409411
let promise: EventLoopPromise<Void>
410412

411413
init(promise: EventLoopPromise<Void>) {
414+
self.lock = Lock()
412415
self.promise = promise
413416
}
414417

418+
var reads: Int {
419+
return self.lock.withLock {
420+
self._reads
421+
}
422+
}
423+
415424
func didReceivePart(task: HTTPClient.Task<Response>, _ buffer: ByteBuffer) -> EventLoopFuture<Void> {
416-
self.reads += 1
425+
self.lock.withLockVoid {
426+
self._reads += 1
427+
}
417428
return self.promise.futureResult
418429
}
419430

0 commit comments

Comments
 (0)