Remove pollOrThrow

This method is better removed, because it doesn't follow the
naming conventions we want to keep in this file. It also isn't
useful :
• There is only one use of it outside tests, and it's in the
  same file. It's trivial to inline it.
• The method has a unit test, which becomes useless once the
  method is inlined.
• There is a corresponding command in the interpreter, but it's
  only used by the unit test and therefore can be removed once
  the unit test is removed.

Test: TH
Bug: 157405399
Change-Id: Ib5b1369ac28e4577adc98204e42ff2f27729e64c
This commit is contained in:
Chalard Jean 2023-02-27 19:13:46 +09:00
commit c2cf7eb82d
2 changed files with 10 additions and 34 deletions

View file

@ -365,18 +365,6 @@ class TestableNetworkCallbackTest {
""")
}
@Test
fun testPollOrThrow() {
assertFails { mCallback.pollOrThrow(SHORT_TIMEOUT_MS) }
TNCInterpreter.interpretTestSpec(initial = mCallback, lineShift = 1,
threadTransform = { cb -> cb.createLinkedCopy() }, spec = """
sleep; onAvailable(133) | pollOrThrow(2) = Available(133) time 1..4
| pollOrThrow(1) fails
onCapabilitiesChanged(108) | pollOrThrow(1) = CapabilitiesChanged(108) time 0..3
onBlockedStatus(199) | pollOrThrow(1) = BlockedStatus(199) time 0..3
""")
}
@Test
fun testEventuallyExpect() {
// TODO: Current test does not verify the inline one. Also verify the behavior after
@ -455,7 +443,6 @@ private val interpretTable = listOf<InterpretMatcher<TestableNetworkCallback>>(
}
},
Regex("""poll\((\d+)\)""") to { i, cb, t -> cb.poll(t.timeArg(1)) },
Regex("""pollOrThrow\((\d+)\)""") to { i, cb, t -> cb.pollOrThrow(t.timeArg(1)) },
// Interpret "eventually(Available(xx), timeout)" as calling eventuallyExpect that expects
// CallbackEntry.AVAILABLE with netId of xx within timeout*INTERPRET_TIME_UNIT timeout, and
// likewise for all callback types.

View file

@ -223,18 +223,6 @@ open class TestableNetworkCallback private constructor(
fun poll(timeoutMs: Long = defaultTimeoutMs, predicate: (CallbackEntry) -> Boolean = { true }) =
history.poll(timeoutMs, predicate)
/**
* Get the next callback or throw if timeout.
*
* With no argument, this method waits out the default timeout. To wait forever, pass
* Long.MAX_VALUE.
*/
@JvmOverloads
fun pollOrThrow(
timeoutMs: Long = defaultTimeoutMs,
errorMsg: String = "Did not receive callback after $timeoutMs"
): CallbackEntry = poll(timeoutMs) ?: fail(errorMsg)
/*****
* expect family of methods.
* These methods fetch the next callback and assert it matches the conditions : type,
@ -350,15 +338,16 @@ open class TestableNetworkCallback private constructor(
timeoutMs: Long = defaultTimeoutMs,
errorMsg: String? = null,
test: (T) -> Boolean = { true }
) = pollOrThrow(timeoutMs, "Did not receive ${T::class.simpleName} after ${timeoutMs}ms").also {
if (it !is T) fail("Expected callback ${T::class.simpleName}, got $it")
if (ANY_NETWORK !== network && it.network != network) {
fail("Expected network $network for callback : $it")
}
if (!test(it)) {
fail("${errorMsg ?: "Callback doesn't match predicate"} : $it")
}
} as T
) = (poll(timeoutMs) ?: fail("Did not receive ${T::class.simpleName} after ${timeoutMs}ms"))
.also {
if (it !is T) fail("Expected callback ${T::class.simpleName}, got $it")
if (ANY_NETWORK !== network && it.network != network) {
fail("Expected network $network for callback : $it")
}
if (!test(it)) {
fail("${errorMsg ?: "Callback doesn't match predicate"} : $it")
}
} as T
inline fun <reified T : CallbackEntry> expect(
network: HasNetwork,