@@ -4,6 +4,7 @@ var d3SelectAll = require('../../strict-d3').selectAll;
44var Plotly = require ( '../../../lib/index' ) ;
55var downloadCSV = require ( './assets/post_process' ) . downloadCSV ;
66var nSamples = require ( './assets/constants' ) . nSamples ;
7+ var MAX_RENDERING_TIME = 4000 ;
78
89var gd = createGraphDiv ( ) ;
910
@@ -277,31 +278,48 @@ describe('Performance test various traces', function() {
277278 tests . forEach ( function ( spec , index ) {
278279 samples . forEach ( function ( t ) {
279280 it ( 'turn: ' + t , function ( done ) {
280- var startTime , endTime ;
281+ if ( t === 0 ) {
282+ tests [ index ] . raw = [ ] ;
283+ }
281284
282- requestAnimationFrame ( function ( ) {
285+ var timerID ;
286+ var requestID1 , requestID2 ;
287+
288+ var startTime , endTime ;
289+
290+ requestID1 = requestAnimationFrame ( function ( ) {
283291 // Wait for actual rendering instead of promise
284- requestAnimationFrame ( function ( ) {
292+ requestID2 = requestAnimationFrame ( function ( ) {
285293 endTime = performance . now ( ) ;
286294
287295 var delta = endTime - startTime ;
288296
289- if ( t === 0 ) {
290- tests [ index ] . raw = [ ] ;
297+ if ( tests [ index ] . raw [ t ] === undefined ) {
298+ tests [ index ] . raw [ t ] = delta ;
291299 }
292- tests [ index ] . raw [ t ] = delta ;
293300
294301 if ( spec . selector ) {
295302 var nodes = d3SelectAll ( spec . selector ) ;
296303 expect ( nodes . size ( ) ) . toEqual ( spec . nTraces ) ;
297304 }
298305
306+ clearTimeout ( timerID ) ;
307+
299308 done ( ) ;
300309 } ) ;
301310 } ) ;
302311
303312 var mock = generateMock ( spec ) ;
304313
314+ timerID = setTimeout ( ( ) => {
315+ tests [ index ] . raw [ t ] = 'none' ;
316+
317+ cancelAnimationFrame ( requestID2 ) ;
318+ cancelAnimationFrame ( requestID1 ) ;
319+
320+ done . fail ( 'Takes too much time' ) ;
321+ } , MAX_RENDERING_TIME ) ;
322+
305323 startTime = performance . now ( ) ;
306324
307325 Plotly . newPlot ( gd , mock ) ;
0 commit comments