mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
[TESTS] Make onDisconnect tests more robust
Before refactoring the function ensure the tests cover all cases. This fixes a bug where the payload ttl was too low in some instances causing backDate to do no work when it should.
This commit is contained in:
parent
c38ff9bf95
commit
688405bc6d
@ -57,7 +57,7 @@ public class P2PDataStoreDisconnectTest {
|
||||
ProtectedStoragePayload protectedStoragePayload = new ExpirableProtectedStoragePayloadStub(ownerKeys.getPublic(), ttl);
|
||||
|
||||
ProtectedStorageEntry protectedStorageEntry = testState.mockedStorage.getProtectedStorageEntry(protectedStoragePayload, ownerKeys);
|
||||
testState.mockedStorage.addProtectedStorageEntry(protectedStorageEntry, TestState.getTestNodeAddress(), null);
|
||||
testState.mockedStorage.addProtectedStorageEntry(protectedStorageEntry, getTestNodeAddress(), null);
|
||||
|
||||
return protectedStorageEntry;
|
||||
}
|
||||
@ -85,17 +85,30 @@ public class P2PDataStoreDisconnectTest {
|
||||
|
||||
// TESTCASE: Bad peer info
|
||||
@Test
|
||||
public void peerConnectionUnknown() {
|
||||
public void peerConnectionUnknown() throws CryptoException, NoSuchAlgorithmException {
|
||||
when(this.mockedConnection.hasPeersNodeAddress()).thenReturn(false);
|
||||
|
||||
ProtectedStorageEntry protectedStorageEntry = populateTestState(testState, 2);
|
||||
|
||||
SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry);
|
||||
|
||||
this.testState.mockedStorage.onDisconnect(CloseConnectionReason.SOCKET_CLOSED, mockedConnection);
|
||||
|
||||
verifyStateAfterDisconnect(this.testState, beforeState, false, false);
|
||||
}
|
||||
|
||||
// TESTCASE: Intended disconnects don't trigger expiration
|
||||
@Test
|
||||
public void connectionClosedIntended() {
|
||||
public void connectionClosedIntended() throws CryptoException, NoSuchAlgorithmException {
|
||||
when(this.mockedConnection.hasPeersNodeAddress()).thenReturn(true);
|
||||
|
||||
ProtectedStorageEntry protectedStorageEntry = populateTestState(testState, 2);
|
||||
|
||||
SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry);
|
||||
|
||||
this.testState.mockedStorage.onDisconnect(CloseConnectionReason.CLOSE_REQUESTED_BY_PEER, mockedConnection);
|
||||
|
||||
verifyStateAfterDisconnect(this.testState, beforeState, false, false);
|
||||
}
|
||||
|
||||
// TESTCASE: Peer NodeAddress unknown
|
||||
@ -104,7 +117,7 @@ public class P2PDataStoreDisconnectTest {
|
||||
when(this.mockedConnection.hasPeersNodeAddress()).thenReturn(true);
|
||||
when(mockedConnection.getPeersNodeAddressOptional()).thenReturn(Optional.empty());
|
||||
|
||||
ProtectedStorageEntry protectedStorageEntry = populateTestState(testState, 1);
|
||||
ProtectedStorageEntry protectedStorageEntry = populateTestState(testState, 2);
|
||||
|
||||
SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry);
|
||||
|
||||
@ -134,7 +147,7 @@ public class P2PDataStoreDisconnectTest {
|
||||
when(this.mockedConnection.hasPeersNodeAddress()).thenReturn(true);
|
||||
when(mockedConnection.getPeersNodeAddressOptional()).thenReturn(Optional.of(new NodeAddress("notTestNode", 2020)));
|
||||
|
||||
ProtectedStorageEntry protectedStorageEntry = populateTestState(testState, 1);
|
||||
ProtectedStorageEntry protectedStorageEntry = populateTestState(testState, 2);
|
||||
|
||||
SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry);
|
||||
|
||||
@ -149,7 +162,7 @@ public class P2PDataStoreDisconnectTest {
|
||||
when(this.mockedConnection.hasPeersNodeAddress()).thenReturn(true);
|
||||
when(mockedConnection.getPeersNodeAddressOptional()).thenReturn(Optional.of(TestState.getTestNodeAddress()));
|
||||
|
||||
ProtectedStorageEntry protectedStorageEntry = populateTestState(testState, 1);
|
||||
ProtectedStorageEntry protectedStorageEntry = populateTestState(testState, 2);
|
||||
|
||||
SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry);
|
||||
|
||||
@ -158,7 +171,7 @@ public class P2PDataStoreDisconnectTest {
|
||||
|
||||
this.testState.mockedStorage.onDisconnect(CloseConnectionReason.SOCKET_CLOSED, mockedConnection);
|
||||
|
||||
verifyStateAfterDisconnect(this.testState, beforeState, true, false);
|
||||
verifyStateAfterDisconnect(this.testState, beforeState, true, true);
|
||||
}
|
||||
|
||||
// TESTCASE: ProtectedStoragePayloads implementing the PersistablePayload interface are correctly removed
|
||||
@ -186,7 +199,7 @@ public class P2PDataStoreDisconnectTest {
|
||||
testState.mockedStorage.getProtectedStorageEntry(protectedStoragePayload, ownerKeys);
|
||||
|
||||
testState.mockedStorage.addProtectedStorageEntry(
|
||||
protectedStorageEntry, TestState.getTestNodeAddress(), null);
|
||||
protectedStorageEntry, getTestNodeAddress(), null);
|
||||
|
||||
SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user