Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add URLEndpointListenerTest.testStopListener #2730

Merged
merged 2 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions Objective-C/Tests/URLEndpointListenerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -1212,4 +1212,45 @@ - (void) testListenerWithImportIdentity {
AssertNil(err);
}

// Disable until CBL-1243 is fixed
- (void) _testStopListener {
XCTestExpectation* x1 = [self expectationWithDescription: @"idle"];
XCTestExpectation* x2 = [self expectationWithDescription: @"offline"];
XCTestExpectation* x3 = [self expectationWithDescription: @"stopped"];

Listener* listener = [self listenWithTLS: NO];

CBLReplicator* replicator = [self replicator: self.otherDB
continous: YES
target: listener.localEndpoint
serverCert: nil];
[replicator addChangeListener: ^(CBLReplicatorChange *change) {
CBLReplicatorActivityLevel level = change.status.activity;
if (level == kCBLReplicatorIdle)
[x1 fulfill];
else if (level == kCBLReplicatorOffline)
[x2 fulfill];
else if (level == kCBLReplicatorStopped)
[x3 fulfill];
}];
[replicator start];

// Wait until idle then stop the listener:
[self waitForExpectations: @[x1] timeout: timeout];

[self stopListen];

// Wait until the replicator is offline then stop the replicator:
[self waitForExpectations: @[x2] timeout: timeout];

// Check error
AssertEqual(replicator.status.error.code, CBLErrorWebSocketGoingAway);

// Stop replicator:
[replicator stop];

// Wait for the replicator to be stopped:
[self waitForExpectations: @[x3] timeout: timeout];
}

@end
42 changes: 42 additions & 0 deletions Swift/Tests/URLEndpointListenerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,48 @@ class URLEndpontListenerTest: ReplicatorTest {
try stopListener(listener: listener!)
XCTAssertNil(listener!.tlsIdentity)
}

// Disable until CBL-1243 is fixed
func _testStopListener() throws {
let x1 = expectation(description: "idle")
let x2 = expectation(description: "offline")
let x3 = expectation(description: "stopped")

let listener = try listen(tls: false)

let repl = replicator(db: self.oDB,
continuous: true,
target: listener.localURLEndpoint,
serverCert: nil)
repl.addChangeListener { (change) in
let activity = change.status.activity
if activity == .idle {
x1.fulfill()
} else if activity == .offline {
x2.fulfill()
} else if activity == .stopped {
x3.fulfill()
}
}
repl.start()

// Wait until idle then stop the listener:
wait(for: [x1], timeout: 5.0)

try stopListen()

// Wait until the replicator is offline then stop the replicator:
wait(for: [x2], timeout: 5.0)

// Check error
XCTAssertEqual((repl.status.error! as NSError).code, CBLErrorWebSocketGoingAway)

// Stop replicator:
repl.stop()

// Wait for the replicator to be stopped:
wait(for: [x3], timeout: 5.0)
}
}

@available(macOS 10.12, iOS 10.0, *)
Expand Down