Skip to content

Commit 0784cf3

Browse files
committed
fix AsyncRecordControllerTest
1 parent e74f0c5 commit 0784cf3

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

library/src/main/java/com/pedro/library/base/recording/AsyncBaseRecordController.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ abstract class AsyncBaseRecordController : RecordController {
185185
onWriteFrame(frame)
186186
} finally {
187187
bufferPool.release(frame.data)
188+
onFrameRecycled()
188189
}
189190
}
190191
}
@@ -222,4 +223,10 @@ abstract class AsyncBaseRecordController : RecordController {
222223
abstract fun startRecordImp(path: String, listener: RecordController.Listener?, tracks: RecordTracks)
223224
abstract fun stopRecordImp()
224225
abstract suspend fun onWriteFrame(frame: MediaFrame)
226+
227+
/**
228+
* Called once the frame buffer went back to the pool, right after onWriteFrame.
229+
* Only meant to let a test sync with the recycling, does nothing by default.
230+
*/
231+
protected open fun onFrameRecycled() {}
225232
}

library/src/test/java/com/pedro/library/base/recording/AsyncBaseRecordControllerTest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.pedro.common.frame.MediaFrame
66
import org.junit.Assert.assertArrayEquals
77
import org.junit.Assert.assertEquals
88
import org.junit.Assert.assertSame
9+
import org.junit.Assert.assertTrue
910
import org.junit.Test
1011
import java.io.FileDescriptor
1112
import java.nio.ByteBuffer
@@ -32,6 +33,9 @@ class AsyncBaseRecordControllerTest {
3233
override suspend fun onWriteFrame(frame: MediaFrame) {
3334
//keep the array identity and the capacity, the buffer itself is recycled right after
3435
written.add(frame.data.array() to frame.data.capacity())
36+
}
37+
38+
override fun onFrameRecycled() {
3539
latch.countDown()
3640
}
3741

@@ -42,7 +46,7 @@ class AsyncBaseRecordControllerTest {
4246
}
4347

4448
fun awaitFrames(count: Int) {
45-
latch.await(1000, TimeUnit.MILLISECONDS)
49+
assertTrue(latch.await(1000, TimeUnit.MILLISECONDS))
4650
latch = CountDownLatch(count)
4751
}
4852
}

0 commit comments

Comments
 (0)