From c69c6b9082d295cca65d4f9170240ed6b2d2a323 Mon Sep 17 00:00:00 2001 From: Salakar Date: Sun, 25 Mar 2018 19:24:18 +0100 Subject: [PATCH] [tests][bridge] added device time drift checks --- tests-new/bridge/env/node/context.js | 30 ++++++++++++++++++++++++++++ tests-new/bridge/env/node/vm.js | 2 -- tests-new/bridge/env/rn.js | 4 ++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/tests-new/bridge/env/node/context.js b/tests-new/bridge/env/node/context.js index d096e068..0c81678e 100644 --- a/tests-new/bridge/env/node/context.js +++ b/tests-new/bridge/env/node/context.js @@ -3,8 +3,10 @@ global.bridge.context = null; const consoleContext = require('./console'); const { createContext } = require('vm'); +const chalk = require('chalk'); let customBridgeProps = []; +let driftCheckStart = null; module.exports = { /** @@ -58,6 +60,34 @@ module.exports = { console: consoleContext(), __bridgeNode: { _ready() { + if (!driftCheckStart) { + driftCheckStart = Date.now(); + global.bridge.context.__driftCheck(1); + } else { + setTimeout(() => process.emit('bridge-attached'), 1); + } + }, + + _callbackDriftCheck() { + const timeTaken = Date.now() - driftCheckStart; + if (timeTaken > 5000) { + console.log( + `${chalk.blue( + '[bridge] ⚠️ ' + )} It looks like there's an issue with device timer performance...` + ); + console.log( + `${chalk.blue( + '[bridge] ⚠️ ' + )} You may experience slow testing times as a result - ensure your device date/time correctly matches your debugger machine.` + ); + // todo android only + // fake the RN warning for this + global.bridge.context.console.warn( + `Debugger and device times have drifted. ` + + `Please correct this by running adb shell "date \`date +%m%d%H%M%Y.%S\`" on your debugger machine.` + ); + } setTimeout(() => process.emit('bridge-attached'), 1); }, diff --git a/tests-new/bridge/env/node/vm.js b/tests-new/bridge/env/node/vm.js index f8de7c81..ac95ea36 100644 --- a/tests-new/bridge/env/node/vm.js +++ b/tests-new/bridge/env/node/vm.js @@ -47,13 +47,11 @@ async function downloadBundle(bundleUrl) { async function getBundle(request) { if (bundle) return bundle; - console.log(''); console.log( `${chalk.blue( '[bridge]' )} debugger has connected! Downloading app JS bundle...` ); - console.log(''); const parsedUrl = url.parse(request.url, true); invariant(parsedUrl.query); diff --git a/tests-new/bridge/env/rn.js b/tests-new/bridge/env/rn.js index 4bd7d9ce..df32549d 100644 --- a/tests-new/bridge/env/rn.js +++ b/tests-new/bridge/env/rn.js @@ -36,6 +36,10 @@ if (Platform.OS === 'ios' && !bridgeNode) { } } +global.__driftCheck = delay => { + setTimeout(bridgeNode._callbackDriftCheck, delay); +}; + let hasInitialized = false; export default {