[gjs: 12/13] test: Remove pending timeout source after test



commit 8791be41dfa9227fea714229c370f4565c93e44f
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Oct 20 19:13:25 2019 -0700

    test: Remove pending timeout source after test
    
    If the whole test file takes more than 15 seconds to execute (for
    example, when running it with GC zeal enabled), the "neverRun" timeout
    will fire and throw an exception, thereby failing the test. Remove the
    timeout source after that particular suite finishes.

 installed-tests/js/testMainloop.js | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/installed-tests/js/testMainloop.js b/installed-tests/js/testMainloop.js
index 8215baef..aff3d5aa 100644
--- a/installed-tests/js/testMainloop.js
+++ b/installed-tests/js/testMainloop.js
@@ -3,7 +3,7 @@
 const Mainloop = imports.mainloop;
 
 describe('Mainloop.timeout_add()', function () {
-    let runTenTimes, runOnlyOnce, neverRun;
+    let runTenTimes, runOnlyOnce, neverRun, neverRunSource;
     beforeAll(function (done) {
         let count = 0;
         runTenTimes = jasmine.createSpy('runTenTimes').and.callFake(() => {
@@ -19,7 +19,7 @@ describe('Mainloop.timeout_add()', function () {
 
         Mainloop.timeout_add(10, runTenTimes);
         Mainloop.timeout_add(10, runOnlyOnce);
-        Mainloop.timeout_add(15000, neverRun);
+        neverRunSource = Mainloop.timeout_add(15000, neverRun);
     });
 
     it('runs a timeout function', function () {
@@ -33,6 +33,10 @@ describe('Mainloop.timeout_add()', function () {
     it('runs a timeout function after an initial timeout', function () {
         expect(neverRun).not.toHaveBeenCalled();
     });
+
+    afterAll(function () {
+        Mainloop.source_remove(neverRunSource);
+    });
 });
 
 describe('Mainloop.idle_add()', function () {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]