diff options
author | Thomas Watson | 2020-05-28 13:19:35 +0000 |
---|---|---|
committer | Thomas Watson | 2020-05-28 13:19:35 +0000 |
commit | ad89a1e5480476468e678e0ff1a0cf4dad854437 (patch) | |
tree | 685e3d4fce04327c2bd2af755019d0ac29e699aa | |
parent | 3171fc3fd4c427273526616f17f5724eb6bfee52 (diff) | |
download | rt.equinox.framework-R4_16_maintenance.tar.gz rt.equinox.framework-R4_16_maintenance.tar.xz rt.equinox.framework-R4_16_maintenance.zip |
Bug 563372 - Be sure to handle async update properlyY20200609-2100Y20200609-0150S4_16_0_RC2R4_16I20200604-0540I20200603-0600I20200602-1800I20200602-0600I20200602-0510I20200602-0010I20200601-1800I20200601-0640I20200601-0140I20200531-1800I20200531-0600I20200530-0600I20200529-0550R4_16_maintenance
testBug258209_1 has a timing issue because the Framework.update
operation is async. This allows the test to try to waitForStop but the
framework may have already be re-activated. Update this test to do what
other tests that update the framework do by calling waitForStop in
another thread before invoking Framework.update.
Change-Id: Iee4de68f05b7cb151be2f61fcad353a625eb455c
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
2 files changed, 43 insertions, 72 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java index ab849d154..75b74e304 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java @@ -308,6 +308,44 @@ public class AbstractBundleTests extends CoreTest { return stop(equinox, true, 10000); } + static public FrameworkEvent update(final Framework equinox) { + final Exception[] failureException = new BundleException[1]; + final FrameworkEvent[] success = new FrameworkEvent[] { null }; + final String uuid = getUUID(equinox); + Thread waitForUpdate = new Thread(new Runnable() { + @Override + public void run() { + success[0] = waitForStop(equinox, uuid, false, 10000); + } + }, "test waitForStop thread"); //$NON-NLS-1$ + waitForUpdate.start(); + + try { + // delay hack to allow waitForUpdate thread to block on waitForStop before we + // update. + Thread.sleep(200); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + fail("unexpected interuption", e); + } + + try { + equinox.update(); + } catch (BundleException e) { + fail("Failed to update the framework", e); //$NON-NLS-1$ + } + try { + waitForUpdate.join(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + fail("unexpected interuption", e); //$NON-NLS-1$ + } + if (failureException[0] != null) { + fail("Error occurred while waiting", failureException[0]); //$NON-NLS-1$ + } + return success[0]; + } + static public FrameworkEvent stop(Framework equinox, boolean quietly, long timeout) { if (equinox == null) return null; diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java index 83b9f3429..b67f9f69a 100755 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java @@ -549,39 +549,9 @@ public class SystemBundleTests extends AbstractBundleTests { fail("Failed to start the framework", e); //$NON-NLS-1$ } assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState()); //$NON-NLS-1$ - final Exception[] failureException = new BundleException[1]; - final FrameworkEvent[] success = new FrameworkEvent[] {null}; - Thread t = new Thread(new Runnable() { - @Override - public void run() { - try { - success[0] = equinox.waitForStop(10000); - } catch (InterruptedException e) { - failureException[0] = e; - } - } - }, "test waitForStop thread"); //$NON-NLS-1$ - t.start(); - try { - // delay hack to allow t thread to block on waitForStop before we update. - Thread.sleep(500); - } catch (InterruptedException e) { - fail("unexpected interuption", e); - } - try { - equinox.update(); - } catch (BundleException e) { - fail("Failed to update the framework", e); //$NON-NLS-1$ - } - try { - t.join(); - } catch (InterruptedException e) { - fail("unexpected interuption", e); //$NON-NLS-1$ - } - if (failureException[0] != null) - fail("Error occurred while waiting", failureException[0]); //$NON-NLS-1$ - assertNotNull("Wait for stop event is null", success[0]); //$NON-NLS-1$ - assertEquals("Wait for stop event type is wrong", FrameworkEvent.STOPPED_UPDATE, success[0].getType()); //$NON-NLS-1$ + + FrameworkEvent success = update(equinox); + assertEquals("Wait for stop event type is wrong", FrameworkEvent.STOPPED_UPDATE, success.getType()); //$NON-NLS-1$ // TODO delay hack to allow the framework to get started again for (int i = 0; i < 5 && Bundle.ACTIVE != equinox.getState(); i++) try { @@ -939,37 +909,7 @@ public class SystemBundleTests extends AbstractBundleTests { openAllBundleFiles(equinox.getBundleContext()); - final Exception[] failureException = new BundleException[1]; - final FrameworkEvent[] success = new FrameworkEvent[] {null}; - Thread waitForUpdate = new Thread(new Runnable() { - @Override - public void run() { - try { - success[0] = equinox.waitForStop(10000); - } catch (InterruptedException e) { - failureException[0] = e; - } - } - }, "test waitForStop thread"); //$NON-NLS-1$ - waitForUpdate.start(); - try { - // delay hack to allow waitForUpdate thread to block on waitForStop before we update. - Thread.sleep(100); - } catch (InterruptedException e) { - fail("unexpected interuption", e); - } - try { - equinox.update(); - } catch (BundleException e) { - fail("Failed to update the framework", e); //$NON-NLS-1$ - } - try { - waitForUpdate.join(); - } catch (InterruptedException e) { - fail("unexpected interuption", e); //$NON-NLS-1$ - } - if (failureException[0] != null) - fail("Error occurred while waiting", failureException[0]); //$NON-NLS-1$ + update(equinox); // we can either have a hack here that waits until the system bundle is active // or we can just try to start it and race with the update() call above @@ -1623,14 +1563,7 @@ public class SystemBundleTests extends AbstractBundleTests { equinox.start(); assertEquals("Unexpected state", Bundle.ACTIVE, testTCCL.getState()); //$NON-NLS-1$ - String uuid = getUUID(equinox); - // test that the correct tccl is used for framework update - try { - equinox.update(); - } catch (Exception e) { - fail("Unexpected exception", e); //$NON-NLS-1$ - } - waitForStop(equinox, uuid, false, 10000); + update(equinox); checkActive(testTCCL); |