Make sure that runToFinish() returns after VM dies

There is a gap between vm.stop() call to complete VM shutdown. So it
could be the case that runToFinish() returns before VM dies, which may
cause confusion. To ensure that, mExecutorService.shutdown() is now only
called from onDied() callback. This also makes the test robust by
implicitly checking whether onDied() is called or not.

Bug: 238692795
Test: atest MicrodroidTests
Change-Id: I4204ff443f3415c6795598c325e03b8bd8fc1f25
diff --git a/tests/helper/src/java/com/android/microdroid/test/device/MicrodroidDeviceTestBase.java b/tests/helper/src/java/com/android/microdroid/test/device/MicrodroidDeviceTestBase.java
index e5bc45a..a07731e 100644
--- a/tests/helper/src/java/com/android/microdroid/test/device/MicrodroidDeviceTestBase.java
+++ b/tests/helper/src/java/com/android/microdroid/test/device/MicrodroidDeviceTestBase.java
@@ -210,9 +210,7 @@
 
         protected void forceStop(VirtualMachine vm) {
             try {
-                vm.clearCallback();
                 vm.stop();
-                mExecutorService.shutdown();
             } catch (VirtualMachineException e) {
                 throw new RuntimeException(e);
             }
@@ -233,6 +231,7 @@
         @Override
         @CallSuper
         public void onDied(VirtualMachine vm, int reason) {
+            vm.clearCallback();
             mExecutorService.shutdown();
         }