test: simplify node setInterval test (#20594)

This commit is contained in:
Jeremy Apthorp 2019-10-15 17:10:28 -07:00 committed by GitHub
parent 93788e76e0
commit 9055b5cf6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -217,35 +217,18 @@ describe('node feature', () => {
describe('setInterval called under blink env in renderer process', () => { describe('setInterval called under blink env in renderer process', () => {
it('can be scheduled in time', (done) => { it('can be scheduled in time', (done) => {
let interval = null const id = setInterval(() => {
let clearing = false clearInterval(id)
const clear = () => {
if (interval === null || clearing) return
// interval might trigger while clearing (remote is slow sometimes)
clearing = true
clearInterval(interval)
clearing = false
interval = null
done() done()
} }, 10)
interval = setInterval(clear, 10)
}) })
it('can be scheduled in time from timers module', (done) => { it('can be scheduled in time from timers module', (done) => {
let interval = null const { setInterval, clearInterval } = require('timers')
let clearing = false const id = setInterval(() => {
const clear = () => { clearInterval(id)
if (interval === null || clearing) return
// interval might trigger while clearing (remote is slow sometimes)
clearing = true
require('timers').clearInterval(interval)
clearing = false
interval = null
done() done()
} }, 10)
interval = require('timers').setInterval(clear, 10)
}) })
}) })
}) })