-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds gzip tests with new accumulator method
- Loading branch information
Kevin Whitley
committed
Jan 11, 2017
1 parent
902a154
commit b5a5fe9
Showing
4 changed files
with
112 additions
and
9 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
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
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
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,62 @@ | ||
var movies = [{ | ||
title: 'The Prestige', | ||
director: 'Christopher Nolan', | ||
},{ | ||
title: 'Schindler\'s List', | ||
director: 'Steven Spielberg' | ||
}] | ||
|
||
var instances = [] | ||
|
||
function MockAPI(expiration, options) { | ||
// console.log('creating MockAPI with expiration in ' + expiration + ' with ApiCache config', options) | ||
var express = require('express') | ||
var compression = require('compression') | ||
var apicache = require('../src/apicache').newInstance(options) | ||
|
||
var app = express() | ||
app.use(compression()) | ||
|
||
instances.push(this) | ||
|
||
this.apicache = apicache | ||
this.id = instances.length | ||
this.app = app | ||
|
||
// console.log('instantiating MockAPI:' + this.id + ' with expiration of ' + expiration) | ||
// console.log('this.id vs this.apicache.id', this.id, this.apicache.id) | ||
instances.forEach((instance, id) => { | ||
// console.log('instance id:apicache.id', instance.id, instance.apicache.id) | ||
if (instance.id !== this.id && this.apicache === instance.apicache) { | ||
console.log('WARNING: SHARED APICACHE INSTANCE', id, this.id, this.apicache.id, instance.apicache.id) | ||
} | ||
if (instance.id !== this.id && this.app === instance.app) { | ||
console.log('WARNING: SHARED EXPRESS INSTANCE', id, this.id) | ||
} | ||
}) | ||
|
||
app.use(this.apicache.middleware(expiration)) | ||
|
||
app.get('/api/gzip/movies', function(req, res) { | ||
app.requestsProcessed++ | ||
|
||
res.json(movies) | ||
}) | ||
|
||
app.get('/api/gzip/writeandend', function(req, res) { | ||
app.requestsProcessed++ | ||
|
||
res.write('a') | ||
res.write('b') | ||
res.write('c') | ||
|
||
res.end() | ||
}) | ||
|
||
app.apicache = apicache | ||
app.requestsProcessed = 0 | ||
|
||
return app | ||
} | ||
|
||
module.exports = function(expiration, config) { return new MockAPI(expiration, config) } |