Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit 33938f9

Browse files
committed
test: check that requests are not opened prematurely (#21)
1 parent 0f46049 commit 33938f9

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

test/test.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,67 @@ test('client.sent', function (t) {
669669
})
670670
})
671671

672+
test('should not open new request until it\'s needed after flush', function (t) {
673+
let client
674+
let requests = 0
675+
let expectRequest = false
676+
const server = APMServer(function (req, res) {
677+
t.equal(expectRequest, true, 'should only send new request when expected')
678+
expectRequest = false
679+
680+
req.resume()
681+
req.on('end', function () {
682+
res.end()
683+
684+
if (++requests === 2) {
685+
server.close()
686+
t.end()
687+
} else {
688+
setTimeout(sendData, 250)
689+
}
690+
})
691+
}).client(function (_client) {
692+
client = _client
693+
sendData()
694+
})
695+
696+
function sendData () {
697+
expectRequest = true
698+
client.sendError({foo: 42})
699+
client.flush()
700+
}
701+
})
702+
703+
test('should not open new request until it\'s needed after timeout', function (t) {
704+
let client
705+
let requests = 0
706+
let expectRequest = false
707+
const server = APMServer(function (req, res) {
708+
t.equal(expectRequest, true, 'should only send new request when expected')
709+
expectRequest = false
710+
711+
req.resume()
712+
req.on('end', function () {
713+
res.end()
714+
715+
if (++requests === 2) {
716+
server.close()
717+
t.end()
718+
} else {
719+
setTimeout(sendData, 250)
720+
}
721+
})
722+
}).client({ time: 1 }, function (_client) {
723+
client = _client
724+
sendData()
725+
})
726+
727+
function sendData () {
728+
expectRequest = true
729+
client.sendError({foo: 42})
730+
}
731+
})
732+
672733
/**
673734
* Side effects
674735
*/

0 commit comments

Comments
 (0)