use of org.awaitility.core.ConditionTimeoutException in project AntennaPod by AntennaPod.
the class EspressoTestUtils method tryKillPlaybackService.
public static void tryKillPlaybackService() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
context.stopService(new Intent(context, PlaybackService.class));
try {
// Android has no reliable way to stop a service instantly.
// Calling stopSelf marks allows the system to destroy the service but the actual call
// to onDestroy takes until the next GC of the system, which we can not influence.
// Try to wait for the service at least a bit.
Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> !PlaybackService.isRunning);
} catch (ConditionTimeoutException e) {
e.printStackTrace();
}
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
}
use of org.awaitility.core.ConditionTimeoutException in project AntennaPod by AntennaPod.
the class AutoDownloadTest method downloadsEnqueuedToAfterCurrent_CurrentAdvancedToNextOnPlaybackComplete.
/**
* A cross-functional test, ensuring playback's behavior works with Auto Download in boundary condition.
*
* Scenario:
* - For setting enqueue location AFTER_CURRENTLY_PLAYING
* - when playback of an episode is complete and the app advances to the next episode (continuous playback on)
* - when automatic download kicks in,
* - ensure the next episode is the current playing one, needed for AFTER_CURRENTLY_PLAYING enqueue location.
*/
@Test
public void downloadsEnqueuedToAfterCurrent_CurrentAdvancedToNextOnPlaybackComplete() throws Exception {
// continuous playback
UserPreferences.setFollowQueue(true);
// Setup: feeds and queue
// downloads 3 of them, leave some in new state (auto-downloadable)
stubFeedsServer.addLocalFeedData(false);
List<FeedItem> queue = DBReader.getQueue();
assertTrue(queue.size() > 1);
FeedItem item0 = queue.get(0);
FeedItem item1 = queue.get(1);
// Actual test
// Play the first one in the queue
playEpisode(item0);
try {
// when playback is complete, advances to the next one, and auto download kicks in,
// ensure that currently playing has been advanced to the next one by this point.
Awaitility.await("advanced to the next episode").atMost(6000, // the test mp3 media is 3-second long. twice should be enough
MILLISECONDS).until(() -> item1.getMedia().getId() == stubDownloadAlgorithm.getCurrentlyPlayingAtDownload());
} catch (ConditionTimeoutException cte) {
long actual = stubDownloadAlgorithm.getCurrentlyPlayingAtDownload();
fail("when auto download is triggered, the next episode should be playing: (" + item1.getId() + ", " + item1.getTitle() + ") . " + "Actual playing: (" + actual + ")");
}
}
use of org.awaitility.core.ConditionTimeoutException in project AntennaPod by AntennaPod.
the class EspressoTestUtils method tryKillDownloadService.
public static void tryKillDownloadService() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
context.stopService(new Intent(context, DownloadService.class));
try {
// Android has no reliable way to stop a service instantly.
// Calling stopSelf marks allows the system to destroy the service but the actual call
// to onDestroy takes until the next GC of the system, which we can not influence.
// Try to wait for the service at least a bit.
Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> !DownloadService.isRunning);
} catch (ConditionTimeoutException e) {
e.printStackTrace();
}
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
}
use of org.awaitility.core.ConditionTimeoutException in project storm by apache.
the class TickTupleTest method testTickTupleWorksWithSystemBolt.
@Test
public void testTickTupleWorksWithSystemBolt() throws Exception {
try (ILocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().build()) {
TopologyBuilder builder = new TopologyBuilder();
FeederSpout feeder = new FeederSpout(new Fields("field1"));
AckFailMapTracker tracker = new AckFailMapTracker();
feeder.setAckFailDelegate(tracker);
builder.setSpout("Spout", feeder);
builder.setBolt("Bolt", new NoopBolt()).shuffleGrouping("Spout");
Config topoConf = new Config();
topoConf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, TICK_INTERVAL_SECS);
try (ILocalTopology topo = cluster.submitTopology("test", topoConf, builder.createTopology())) {
// Use a bootstrap tuple to wait for topology to be running
feeder.feed(new Values("val"), 1);
AssertLoop.assertAcked(tracker, 1);
/*
* Verify that some ticks are received. The interval between ticks is validated by the bolt.
* Too few and the checks will time out. Too many and the bolt may crash (not reliably, but the test should become flaky).
*/
try {
cluster.advanceClusterTime(TICK_INTERVAL_SECS);
waitForTicks(1);
cluster.advanceClusterTime(TICK_INTERVAL_SECS);
waitForTicks(2);
cluster.advanceClusterTime(TICK_INTERVAL_SECS);
waitForTicks(3);
} catch (ConditionTimeoutException e) {
throw new AssertionError(e.getMessage());
}
assertNull("The bolt got a tuple that is not a tick tuple " + nonTickTuple.get(), nonTickTuple.get());
}
}
}
Aggregations