VirtualBox

Changeset 99100 in vbox


Ignore:
Timestamp:
Mar 21, 2023 5:25:26 PM (23 months ago)
Author:
vboxsync
Message:

ValidationKit/tests/api/tdTreeDepth1.py: Rather than include a delay
which waits for Machine::uninit() to be called to close the attached
media after the reference count of the IMachine object ('oVM') has
dropped to zero we can instead trigger Python's garbage collector
directly (gc.collect()) which avoids the need for waiting.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/api/tdTreeDepth1.py

    r99084 r99100  
    4545import sys
    4646import random
    47 import time
     47import gc
    4848
    4949# Only the main script needs to modify the path.
     
    238238        oVM = None;
    239239
    240         # Fudge factor: When unregistering a VM with CleanupMode_UnregisterOnly the
    241         # associated medium objects will be closed when the Machine object is
    242         # uninitialized so wait for that to complete.  Otherwise the check for
    243         # cBaseImages below will race with the VM uninitialization and depending on
    244         # which one wins can cause a test failure.
    245         reporter.log('Waiting five seconds for Machine::uninit() to be called to close the attached disks');
    246         time.sleep(5);
     240        # When unregistering a VM with CleanupMode_UnregisterOnly the associated medium's
     241        # objects will be closed when the corresponding Machine object ('oVM') is
     242        # uninitialized.  Assigning the 'None' object to 'oVM' will cause Python to delete
     243        # the object when the garbage collector runs however this can take several seconds
     244        # so we invoke the Python garbage collector manually here so we don't have to wait.
     245        reporter.log('Invoking python garbage collection to trigger Machine::uninit() which will close the attached disks');
     246        try:
     247            gc.collect();
     248        except:
     249            reporter.logXcpt();
    247250
    248251        cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(oVBox, 'hardDisks'));
     
    328331        oVM = None;
    329332
    330         # Fudge factor: When unregistering a VM with CleanupMode_UnregisterOnly the
    331         # associated medium objects will be closed when the Machine object is
    332         # uninitialized so wait for that to complete.  Otherwise the check for
    333         # cBaseImages below will race with the VM uninitialization and depending on
    334         # which one wins can cause a test failure.
    335         reporter.log('Waiting five seconds for Machine::uninit() to be called to close the attached disks');
    336         time.sleep(5);
     333        # When unregistering a VM with CleanupMode_UnregisterOnly the associated medium's
     334        # objects will be closed when the corresponding Machine object ('oVM') is
     335        # uninitialized.  Assigning the 'None' object to 'oVM' will cause Python to delete
     336        # the object when the garbage collector runs however this can take several seconds
     337        # so we invoke the Python garbage collector manually here so we don't have to wait.
     338        reporter.log('Invoking python garbage collection to trigger Machine::uninit() which will close the attached disks');
     339        try:
     340            gc.collect();
     341        except:
     342            reporter.logXcpt();
    337343
    338344        cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(oVBox, 'hardDisks'))
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette