From ba957e35fff12bd0aa201807546c43c8200c7894 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 1 Mar 2017 10:57:43 -0800 Subject: [PATCH] [node] Don't call callbacks synchronously Fixes memory.test.js deadlock. --- platform/node/test/memory.test.js | 40 ++++++++++++++++--------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/platform/node/test/memory.test.js b/platform/node/test/memory.test.js index e23cb60f89c..b87220b31d8 100644 --- a/platform/node/test/memory.test.js +++ b/platform/node/test/memory.test.js @@ -34,25 +34,27 @@ test('Memory', function(t) { var options = { request: function(req, callback) { - if (req.url == null) { - t.fail('invalid file request'); - } else if (req.url.indexOf('sprite') > -1 && req.url.endsWith('json')) { - callback(null, { data: sprite_json }); - } else if (req.url.indexOf('sprite') > -1 && req.url.endsWith('png')) { - callback(null, { data: sprite_png }); - } else if (req.url.indexOf('fonts') > -1 && req.url.endsWith('pbf')) { - callback(null, { data: glyph }); - } else if (req.url.endsWith('mapbox.satellite')) { - callback(null, { data: source_raster }); - } else if (req.url.indexOf('satellite') > -1 && (req.url.endsWith('png') || req.url.endsWith('webp'))) { - callback(null, { data: tile_raster }); - } else if (req.url.endsWith('mapbox.mapbox-streets-v7')) { - callback(null, { data: source_vector }); - } else if (req.url.indexOf('streets') > -1 && req.url.endsWith('pbf')) { - callback(null, { data: tile_vector }); - } else { - t.fail('unhandled file request: ' + req.url); - } + setTimeout(function () { + if (req.url == null) { + t.fail('invalid file request'); + } else if (req.url.indexOf('sprite') > -1 && req.url.endsWith('json')) { + callback(null, { data: sprite_json }); + } else if (req.url.indexOf('sprite') > -1 && req.url.endsWith('png')) { + callback(null, { data: sprite_png }); + } else if (req.url.indexOf('fonts') > -1 && req.url.endsWith('pbf')) { + callback(null, { data: glyph }); + } else if (req.url.endsWith('mapbox.satellite')) { + callback(null, { data: source_raster }); + } else if (req.url.indexOf('satellite') > -1 && (req.url.endsWith('png') || req.url.endsWith('webp'))) { + callback(null, { data: tile_raster }); + } else if (req.url.endsWith('mapbox.mapbox-streets-v7')) { + callback(null, { data: source_vector }); + } else if (req.url.indexOf('streets') > -1 && req.url.endsWith('pbf')) { + callback(null, { data: tile_vector }); + } else { + t.fail('unhandled file request: ' + req.url); + } + }, 0); }, ratio: testParams.ratio, };