private void waitForAllNetworksToDisconnect() throws Exception {
    final SettableFuture<Void> future = SettableFuture.create();

    BroadcastReceiver receiver =
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context ctx, Intent intent) {
            Network[] networks = connManager.getAllNetworks();
            for (Network network : networks) {
              NetworkInfo info = connManager.getNetworkInfo(network);
              if (info != null && info.isAvailable()) {
                // not done yet
                return;
              }
            }

            future.set(null);
          }
        };

    testContext.registerReceiver(
        receiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    try {
      future.get(NETWORK_STATE_CHANGE_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    } finally {
      testContext.unregisterReceiver(receiver);
    }
  }
How long we're willing to wait for a job to run after it becomes eligible.
jobdispatcher/src/androidTest/java/com/firebase/jobdispatcher/AirplaneModeAndroidTest.java