[Pkg-javascript-commits] [node-tap] 75/186: Add tests for timeout behavior

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 16:40:45 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-tap.

commit b1d40425d6c55b6c33dfa8db9a594c4cd719bfd6
Author: isaacs <i at izs.me>
Date:   Thu Nov 9 11:12:38 2017 -0800

    Add tests for timeout behavior
---
 lib/test.js                            |  11 ++-
 tap-snapshots/unit-test.js-TAP.test.js | 158 ++++++++++++++++++++++++++++++++-
 unit/test.js                           |  61 ++++++++++++-
 3 files changed, 223 insertions(+), 7 deletions(-)

diff --git a/lib/test.js b/lib/test.js
index e99559e..1599873 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -131,6 +131,12 @@ class Test extends Base {
   }
 
   sub (Class, extra, caller) {
+    if (this.results || this.ended) {
+      const er = new Error('cannot create subtest after parent test end')
+      this.threw(er)
+      return Promise.resolve(this)
+    }
+
     if (!extra.skip && this.grep.length) {
       const m = this.grep[0].test(extra.name)
       const match = this.grepInvert ? !m : m
@@ -711,12 +717,11 @@ class Test extends Base {
   }
 
   maybeAutoend () {
-    if (this.autoendTimer)
-      clearTimeout(this.autoendTimer)
-
     if (this.shouldAutoend()) {
+      clearTimeout(this.autoendTimer)
       this.autoendTimer = setTimeout(() => {
         if (this.shouldAutoend()) {
+          clearTimeout(this.autoendTimer)
           this.autoendTimer = setTimeout(() => {
             if (this.shouldAutoend())
               this.end(IMPLICIT)
diff --git a/tap-snapshots/unit-test.js-TAP.test.js b/tap-snapshots/unit-test.js-TAP.test.js
index 5f68f90..51403f9 100644
--- a/tap-snapshots/unit-test.js-TAP.test.js
+++ b/tap-snapshots/unit-test.js-TAP.test.js
@@ -2144,7 +2144,36 @@ ok 1 - this should automatically end # {time}
     1..2
 ok 2 - this should also end # {time}
 
-1..2
+# Subtest: autoend async 1
+    # Subtest: st
+        1..0
+    ok 1 - st # {time}
+    
+    1..1
+ok 3 - autoend async 1 # {time}
+
+# Subtest: autoend async 2
+    # Subtest: st
+        1..0
+    ok 1 - st # {time}
+    
+    1..1
+ok 4 - autoend async 2 # {time}
+
+# Subtest: autoend async limit
+    1..0
+ok 5 - autoend async limit # {time}
+
+not ok 6 - cannot create subtest after parent test end # {time}
+  ---
+  stack: |
+    {STACK}
+  autoend: true
+  test: autoend async limit
+  ...
+
+1..6
+# failed 1 of 6 tests
 
 `
 
@@ -2281,6 +2310,133 @@ parent ae child
 
 `
 
+exports[` TAP assertions and weird stuff timeout expiration > timeout expiration 1`] = `
+TAP version 13
+# Subtest: get lost buf=false
+    not ok 1 - timeout!
+      ---
+      expired: get lost buf=false
+      timeout: 1
+      stack: |
+        {STACK}
+      test: get lost buf=false
+      ...
+    
+    1..1
+    # failed 1 test
+not ok 1 - get lost buf=false # {time}
+  ---
+  timeout: 1
+  ...
+
+not ok 2 - get lost buf=true # {time}
+  ---
+  timeout: 1
+  ...
+{
+    not ok 1 - timeout!
+      ---
+      expired: get lost buf=true
+      timeout: 1
+      stack: |
+        {STACK}
+      test: get lost buf=true
+      ...
+    
+    1..1
+    # failed 1 test
+}
+
+1..2
+# failed 2 of 2 tests
+
+`
+
+exports[` TAP assertions and weird stuff timeout with subs > timeout with subs 1`] = `
+TAP version 13
+# Subtest: get lost buf=false
+    # Subtest: carry on
+        not ok 1 - timeout!
+          ---
+          expired: get lost buf=false
+          stack: |
+            {STACK}
+          test: carry on
+          ...
+        
+        1..1
+        # failed 1 test
+    not ok 1 - carry on # {time}
+    
+    1..1
+    # failed 1 test
+not ok 1 - get lost buf=false # {time}
+  ---
+  timeout: 1
+  ...
+
+not ok 2 - get lost buf=true # {time}
+  ---
+  timeout: 1
+  ...
+{
+    # Subtest: carry on
+        not ok 1 - timeout!
+          ---
+          expired: get lost buf=true
+          stack: |
+            {STACK}
+          test: carry on
+          ...
+        
+        1..1
+        # failed 1 test
+    not ok 1 - carry on # {time}
+    
+    1..1
+    # failed 1 test
+}
+
+1..2
+# failed 2 of 2 tests
+
+`
+
+exports[` TAP assertions and weird stuff timeout at the last tick > timeout at the last tick 1`] = `
+TAP version 13
+# Subtest: work it harder buf=false
+    1..1
+    ok 1 - this is fine
+ok 1 - work it harder buf=false # {time}
+
+not ok 2 - timeout! # {time}
+  ---
+  expired: work it harder buf=false
+  timeout: 1
+  stack: |
+    {STACK}
+  test: work it harder buf=false
+  ...
+
+ok 3 - work it harder buf=true # {time} {
+    1..1
+    ok 1 - this is fine
+}
+
+not ok 4 - timeout!
+  ---
+  expired: work it harder buf=true
+  timeout: 1
+  stack: |
+    {STACK}
+  test: work it harder buf=true
+  ...
+
+1..4
+# failed 2 of 4 tests
+
+`
+
 exports[` TAP addAssert > using the custom isUrl assertion 1`] = `
 TAP version 13
 not ok 1 - expect a valid http/https url
diff --git a/unit/test.js b/unit/test.js
index e83b1d3..b3b1b47 100644
--- a/unit/test.js
+++ b/unit/test.js
@@ -6,7 +6,8 @@ const EE = require('events').EventEmitter
 const MiniPass = require('minipass')
 
 // set this forcibly so it doesn't interfere with other tests.
-process.env.TAP_DIAG === ''
+process.env.TAP_DIAG = ''
+process.env.TAP_BAIL = ''
 
 const clean = out => out
   .replace(/ # time=[0-9\.]+m?s( \{.*)?\n/g, ' # {time}$1\n')
@@ -631,6 +632,22 @@ t.test('assertions and weird stuff', t => {
         setTimeout(() => t.pass('also fine'))
         t.autoend()
       })
+      tt.test('autoend async 1', t => {
+        setTimeout(() =>
+          t.test('st', t => setTimeout(() => t.end())))
+        t.autoend()
+      })
+      tt.test('autoend async 2', t => {
+        setTimeout(() => setTimeout(() =>
+          t.test('st', t => setTimeout(() => t.end()))))
+        t.autoend()
+      })
+      tt.test('autoend async limit', t => {
+        setTimeout(() => setTimeout(() => setTimeout(() =>
+          t.test('st', t => setTimeout(() => t.end())))))
+        t.autoend()
+      })
+
     },
 
     'endAll with test children': tt => {
@@ -708,6 +725,46 @@ t.test('assertions and weird stuff', t => {
       tt.end()
     },
 
+    'timeout expiration': t => {
+      const buf = [ false, true ]
+      buf.forEach(buf => {
+        t.test('get lost buf=' + buf, { buffered: buf, timeout: 1 }, t => {
+          const timer = setTimeout(() => {}, 10000)
+          t.on('timeout', () => clearTimeout(timer))
+        })
+      })
+      t.end()
+    },
+
+    'timeout with subs': t => {
+      const buf = [ false, true ]
+      buf.forEach(buf => {
+        t.test('get lost buf=' + buf, { buffered: buf, timeout: 1 }, t => {
+          const timer = setTimeout(() => {}, 10000)
+          t.test('carry on', t => t.on('timeout', () => clearTimeout(timer)))
+        })
+      })
+      t.end()
+    },
+
+    'timeout at the last tick': t => {
+      const buf = [ false, true ]
+      buf.forEach(buf => {
+        t.test('work it harder buf=' + buf, { buffered: buf, timeout: 1 }, t => {
+          const fs = require('fs')
+          t.plan(1)
+          const start = Date.now()
+          const finish = start + 10
+          while (finish > Date.now()) {
+            fs.readFileSync(__filename)
+          }
+          t.pass('this is fine')
+        })
+      })
+      t.end()
+    },
+
+
   }
 
   const keys = Object.keys(cases)
@@ -770,5 +827,3 @@ t.test('addAssert', t => {
 
 t.test('snapshots')
 t.test('spawn')
-t.test('stdin')
-t.test('timeout')

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-tap.git



More information about the Pkg-javascript-commits mailing list