-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: in addition to cancellation support
- Loading branch information
1 parent
94c2e30
commit 54d27f6
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
// Run with: node --expose-gc ./test/fixtures/memory-usage/aborted-requests.js | ||
|
||
var _ = require('lodash'); | ||
var Bluebird = require('bluebird'); | ||
var rp = require('../../../'); | ||
// var rp = require('request'); | ||
|
||
|
||
var requests = []; | ||
function createRequest(retain) { | ||
|
||
var request = rp('http://localhost:4000'); | ||
request.abort(); | ||
|
||
if (retain) { | ||
requests.push(request); | ||
} | ||
|
||
} | ||
|
||
function checkMemory() { | ||
global.gc(); // Requires the --expose-gc option | ||
console.log(process.memoryUsage().heapUsed + ' bytes in use'); | ||
} | ||
|
||
Bluebird.resolve() | ||
.delay(1000) | ||
.then(checkMemory) | ||
.then(function () { | ||
|
||
_.times(100000, function () { | ||
|
||
createRequest(false); // Should be garbage collected because no reference is kept | ||
|
||
}); | ||
|
||
}) | ||
.delay(1000) | ||
.then(checkMemory) | ||
.then(function () { | ||
|
||
_.times(100000, function () { | ||
|
||
createRequest(true); // Should NOT be garbage collected because reference is kept in requests | ||
|
||
}); | ||
|
||
}) | ||
.delay(1000) | ||
.then(checkMemory); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters