Skip to content

Commit

Permalink
fixup! Fix "removePeerConnection" not being thread-safe
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Dec 11, 2024
1 parent 9f17211 commit 4ab45b9
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class PeerConnectionWrapperTest {
// Add data channels with duplicated labels (from the second data channel and onwards) to test that
// they are correctly disposed also in that case (which should not happen anyway, but just in case).
Mockito.`when`(mockedRandomIdDataChannels[j].label())
.thenAnswer(ReturnValueOrThrowIfDisposed("random-id-" + ((j+1) / 2)))
.thenAnswer(ReturnValueOrThrowIfDisposed("random-id-" + ((j + 1) / 2)))
Mockito.`when`(mockedRandomIdDataChannels[j].state())
.thenAnswer(ReturnValueOrThrowIfDisposed(DataChannel.State.OPEN))

Expand All @@ -544,7 +544,8 @@ class PeerConnectionWrapperTest {
doAnswer { invocation ->
if (Mockito.mockingDetails(invocation.mock).invocations.find {
it!!.method.name === "dispose"
} !== null) {
} !== null
) {
throw IllegalStateException("DataChannel has been disposed")
}

Expand Down Expand Up @@ -574,7 +575,7 @@ class PeerConnectionWrapperTest {
val removePeerConnectionThread = thread {
try {
peerConnectionWrapper!!.removePeerConnection()
} catch(e: Exception) {
} catch (e: Exception) {
exceptionRemovePeerConnection = e
}
}
Expand Down Expand Up @@ -644,7 +645,7 @@ class PeerConnectionWrapperTest {
for (j in 0..<dataChannelMessageCount) {
peerConnectionWrapper!!.send(DataChannelMessage("the-message-type-$j"))
}
} catch(e: Exception) {
} catch (e: Exception) {
exceptionSend = e
}
}
Expand Down Expand Up @@ -697,7 +698,8 @@ class PeerConnectionWrapperTest {
val statusDataChannelObserverArgumentCaptor: ArgumentCaptor<DataChannel.Observer> =
ArgumentCaptor.forClass(DataChannel.Observer::class.java)

doNothing().`when`(mockedStatusDataChannel).registerObserver(statusDataChannelObserverArgumentCaptor.capture())
doNothing().`when`(mockedStatusDataChannel)
.registerObserver(statusDataChannelObserverArgumentCaptor.capture())

peerConnectionWrapper = PeerConnectionWrapper(
mockedPeerConnectionFactory,
Expand Down

0 comments on commit 4ab45b9

Please sign in to comment.