This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for timeout and when the request fails.
- Loading branch information
Showing
2 changed files
with
126 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,59 @@ | ||
'use strict'; | ||
|
||
var mockfs = require('../mockfs'); | ||
var mbgl = require('../../index'); | ||
var test = require('tape'); | ||
|
||
function asyncReply(callback, data) { | ||
setTimeout(function() { callback(null, { data: data }); }, 0); | ||
}; | ||
|
||
function asyncFail(callback) { | ||
setTimeout(function() { callback(new Error('not found')); }, 0); | ||
}; | ||
|
||
function failRequest(t, style, failedResource) { | ||
var options = { | ||
request: function(req, callback) { | ||
var data = mockfs.dataForRequest(req); | ||
|
||
if (failedResource != data) { | ||
asyncReply(callback, data); | ||
} else { | ||
asyncFail(callback); | ||
} | ||
}, | ||
ratio: 2, | ||
}; | ||
|
||
var map = new mbgl.Map(options); | ||
map.load(style); | ||
|
||
map.render({ zoom: 16 }, function(err, pixels) { | ||
if (err) { | ||
t.pass("pass"); | ||
map.release(); | ||
} | ||
}); | ||
}; | ||
|
||
test('Vector', function(t) { | ||
t.plan(5); | ||
|
||
failRequest(t, mockfs.style_vector, null); | ||
failRequest(t, mockfs.style_vector, mockfs.sprite_png); | ||
failRequest(t, mockfs.style_vector, mockfs.sprite_json); | ||
failRequest(t, mockfs.style_vector, mockfs.source_vector); | ||
failRequest(t, mockfs.style_vector, mockfs.tile_vector); | ||
failRequest(t, mockfs.style_vector, mockfs.glyph); | ||
}); | ||
|
||
test('Raster', function(t) { | ||
t.plan(4); | ||
|
||
failRequest(t, mockfs.style_raster, null); | ||
failRequest(t, mockfs.style_raster, mockfs.sprite_png); | ||
failRequest(t, mockfs.style_raster, mockfs.sprite_json); | ||
failRequest(t, mockfs.style_raster, mockfs.source_raster); | ||
failRequest(t, mockfs.style_raster, mockfs.tile_raster); | ||
}); |
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,67 @@ | ||
'use strict'; | ||
|
||
var mockfs = require('../mockfs'); | ||
var mbgl = require('../../index'); | ||
var test = require('tape'); | ||
var timeout = 2000; | ||
|
||
function asyncReply(callback, data) { | ||
setTimeout(function() { callback(null, { data: data }); }, 0); | ||
}; | ||
|
||
function timeoutRequest(t, style, timeoutedResource) { | ||
var options = { | ||
request: function(req, callback) { | ||
var data = mockfs.dataForRequest(req); | ||
|
||
if (timeoutedResource != data) { | ||
asyncReply(callback, data); | ||
} else { | ||
setTimeout(function() { callback(null, { data: data }); t.pass("callback"); }, timeout); | ||
} | ||
}, | ||
ratio: 2, | ||
}; | ||
|
||
var map = new mbgl.Map(options); | ||
map.load(style); | ||
|
||
map.render({ zoom: 16 }, function(err, pixels) { | ||
t.fail("fail"); | ||
}); | ||
|
||
setTimeout(function() { | ||
map.release(); | ||
t.pass("release"); | ||
}, timeout / 2); | ||
}; | ||
|
||
test('Vector', function(t) { | ||
// 1 sprite.png | ||
// 1 spring.json | ||
// 1 source | ||
// 4 tiles | ||
// 7 glyphs | ||
// 5 map.release() | ||
t.plan(19); | ||
|
||
timeoutRequest(t, mockfs.style_vector, mockfs.sprite_png); | ||
timeoutRequest(t, mockfs.style_vector, mockfs.sprite_json); | ||
timeoutRequest(t, mockfs.style_vector, mockfs.source_vector); | ||
timeoutRequest(t, mockfs.style_vector, mockfs.tile_vector); | ||
timeoutRequest(t, mockfs.style_vector, mockfs.glyph); | ||
}); | ||
|
||
test('Raster', function(t) { | ||
// 1 sprite.png | ||
// 1 spring.json | ||
// 1 source | ||
// 4 tiles | ||
// 4 map.release() | ||
t.plan(11); | ||
|
||
timeoutRequest(t, mockfs.style_raster, mockfs.sprite_png); | ||
timeoutRequest(t, mockfs.style_raster, mockfs.sprite_json); | ||
timeoutRequest(t, mockfs.style_raster, mockfs.source_raster); | ||
timeoutRequest(t, mockfs.style_raster, mockfs.tile_raster); | ||
}); |