[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
/**
|
2016-06-13 15:23:23 +00:00
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-06-13 15:23:23 +00:00
|
|
|
*
|
2017-11-02 13:14:11 +00:00
|
|
|
* @emails oncall+react_native
|
2017-12-11 15:59:45 +00:00
|
|
|
* @format
|
[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-06-13 15:23:23 +00:00
|
|
|
let MessageQueue;
|
2016-09-23 18:12:54 +00:00
|
|
|
let MessageQueueTestModule;
|
2016-06-13 15:23:23 +00:00
|
|
|
let queue;
|
[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
|
2016-06-13 15:23:23 +00:00
|
|
|
const MODULE_IDS = 0;
|
|
|
|
const METHOD_IDS = 1;
|
|
|
|
const PARAMS = 2;
|
[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
|
2016-06-13 15:23:23 +00:00
|
|
|
const assertQueue = (flushedQueue, index, moduleID, methodID, params) => {
|
[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
expect(flushedQueue[MODULE_IDS][index]).toEqual(moduleID);
|
|
|
|
expect(flushedQueue[METHOD_IDS][index]).toEqual(methodID);
|
|
|
|
expect(flushedQueue[PARAMS][index]).toEqual(params);
|
|
|
|
};
|
|
|
|
|
2016-06-13 15:23:23 +00:00
|
|
|
// Important things to test:
|
|
|
|
//
|
|
|
|
// [x] Local modules can be invoked through the queue.
|
|
|
|
//
|
|
|
|
// [ ] Local modules that throw exceptions are gracefully caught. In that case
|
|
|
|
// local callbacks stored by IDs are cleaned up.
|
|
|
|
describe('MessageQueue', function() {
|
|
|
|
beforeEach(function() {
|
2016-12-19 01:02:57 +00:00
|
|
|
jest.resetModules();
|
2016-06-13 15:23:23 +00:00
|
|
|
MessageQueue = require('MessageQueue');
|
2016-09-23 18:12:54 +00:00
|
|
|
MessageQueueTestModule = require('MessageQueueTestModule');
|
|
|
|
queue = new MessageQueue();
|
2016-06-13 15:23:23 +00:00
|
|
|
queue.registerCallableModule(
|
2016-09-23 18:12:54 +00:00
|
|
|
'MessageQueueTestModule',
|
2017-12-11 15:59:45 +00:00
|
|
|
MessageQueueTestModule,
|
2016-06-13 15:23:23 +00:00
|
|
|
);
|
2017-12-11 15:59:45 +00:00
|
|
|
queue.createDebugLookup(0, 'MessageQueueTestModule', [
|
|
|
|
'testHook1',
|
|
|
|
'testHook2',
|
|
|
|
]);
|
[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should enqueue native calls', () => {
|
2016-09-23 18:12:54 +00:00
|
|
|
queue.enqueueNativeCall(0, 1, [2]);
|
2016-08-09 13:32:41 +00:00
|
|
|
const flushedQueue = queue.flushedQueue();
|
[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
assertQueue(flushedQueue, 0, 0, 1, [2]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call a local function with the function name', () => {
|
2018-01-08 21:57:51 +00:00
|
|
|
MessageQueueTestModule.testHook2 = jest.fn();
|
|
|
|
expect(MessageQueueTestModule.testHook2.mock.calls.length).toEqual(0);
|
2016-09-23 18:12:54 +00:00
|
|
|
queue.__callFunction('MessageQueueTestModule', 'testHook2', [2]);
|
2018-01-08 21:57:51 +00:00
|
|
|
expect(MessageQueueTestModule.testHook2.mock.calls.length).toEqual(1);
|
[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should store callbacks', () => {
|
2016-09-23 18:12:54 +00:00
|
|
|
queue.enqueueNativeCall(0, 1, ['foo'], null, null);
|
2016-08-09 13:32:41 +00:00
|
|
|
const flushedQueue = queue.flushedQueue();
|
2016-09-23 18:12:54 +00:00
|
|
|
assertQueue(flushedQueue, 0, 0, 1, ['foo']);
|
[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
});
|
|
|
|
|
2015-12-22 19:40:16 +00:00
|
|
|
it('should call the stored callback', () => {
|
2016-09-23 18:12:54 +00:00
|
|
|
let done = false;
|
2017-12-11 15:59:45 +00:00
|
|
|
queue.enqueueNativeCall(
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
[],
|
|
|
|
() => {},
|
|
|
|
() => {
|
|
|
|
done = true;
|
|
|
|
},
|
|
|
|
);
|
2017-10-10 23:20:15 +00:00
|
|
|
queue.__invokeCallback(1, []);
|
[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
expect(done).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw when calling the same callback twice', () => {
|
2016-09-23 18:12:54 +00:00
|
|
|
queue.enqueueNativeCall(0, 1, [], () => {}, () => {});
|
2017-10-10 23:20:15 +00:00
|
|
|
queue.__invokeCallback(1, []);
|
|
|
|
expect(() => queue.__invokeCallback(1, [])).toThrow();
|
[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw when calling both success and failure callback', () => {
|
2016-09-23 18:12:54 +00:00
|
|
|
queue.enqueueNativeCall(0, 1, [], () => {}, () => {});
|
2017-10-10 23:20:15 +00:00
|
|
|
queue.__invokeCallback(1, []);
|
|
|
|
expect(() => queue.__invokeCallback(0, [])).toThrow();
|
[ReactNative] Refactor BatchedBridge and MessageQueue
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
2015-06-17 14:51:48 +00:00
|
|
|
});
|
2017-06-08 19:40:19 +00:00
|
|
|
|
|
|
|
it('should throw when calling with unknown module', () => {
|
2017-12-11 15:59:45 +00:00
|
|
|
const unknownModule = 'UnknownModule',
|
|
|
|
unknownMethod = 'UnknownMethod';
|
2017-06-08 19:40:19 +00:00
|
|
|
expect(() => queue.__callFunction(unknownModule, unknownMethod)).toThrow(
|
|
|
|
`Module ${unknownModule} is not a registered callable module (calling ${unknownMethod})`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return lazily registered module', () => {
|
2017-12-11 15:59:45 +00:00
|
|
|
const dummyModule = {},
|
|
|
|
name = 'modulesName';
|
2017-06-08 19:40:19 +00:00
|
|
|
queue.registerLazyCallableModule(name, () => dummyModule);
|
2017-07-03 14:44:38 +00:00
|
|
|
|
|
|
|
expect(queue.getCallableModule(name)).toEqual(dummyModule);
|
2017-06-08 19:40:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not initialize lazily registered module before it was used for the first time', () => {
|
2017-12-11 15:59:45 +00:00
|
|
|
const dummyModule = {},
|
|
|
|
name = 'modulesName';
|
2017-06-08 19:40:19 +00:00
|
|
|
const factory = jest.fn(() => dummyModule);
|
|
|
|
queue.registerLazyCallableModule(name, factory);
|
|
|
|
expect(factory).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should initialize lazily registered module only once', () => {
|
2017-12-11 15:59:45 +00:00
|
|
|
const dummyModule = {},
|
|
|
|
name = 'modulesName';
|
2017-06-08 19:40:19 +00:00
|
|
|
const factory = jest.fn(() => dummyModule);
|
|
|
|
queue.registerLazyCallableModule(name, factory);
|
2017-07-03 14:44:38 +00:00
|
|
|
queue.getCallableModule(name);
|
|
|
|
queue.getCallableModule(name);
|
2017-06-08 19:40:19 +00:00
|
|
|
expect(factory).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
2017-12-11 15:59:45 +00:00
|
|
|
|
2018-04-03 12:59:07 +00:00
|
|
|
it('should check if the global error handler is not overriden by the DebuggerInternal object', () => {
|
|
|
|
const dummyModule = {
|
|
|
|
dummy: function() {},
|
2017-12-11 15:59:45 +00:00
|
|
|
};
|
2018-04-03 12:59:07 +00:00
|
|
|
const name = 'emptyModuleName';
|
|
|
|
const factory = jest.fn(() => dummyModule);
|
|
|
|
queue.__shouldPauseOnThrow = jest.fn(() => false);
|
2017-12-11 15:59:45 +00:00
|
|
|
queue.registerLazyCallableModule(name, factory);
|
2018-04-03 12:59:07 +00:00
|
|
|
queue.callFunctionReturnFlushedQueue(name, 'dummy', []);
|
|
|
|
expect(queue.__shouldPauseOnThrow).toHaveBeenCalledTimes(2);
|
2017-12-11 15:59:45 +00:00
|
|
|
});
|
|
|
|
|
2018-04-03 12:59:07 +00:00
|
|
|
it('should check if the global error handler is overriden by the DebuggerInternal object', () => {
|
|
|
|
const dummyModule = {
|
|
|
|
dummy: function() {},
|
2017-12-11 15:59:45 +00:00
|
|
|
};
|
2018-04-03 12:59:07 +00:00
|
|
|
const name = 'emptyModuleName';
|
|
|
|
const factory = jest.fn(() => dummyModule);
|
|
|
|
queue.__shouldPauseOnThrow = jest.fn(() => true);
|
2017-12-11 15:59:45 +00:00
|
|
|
queue.registerLazyCallableModule(name, factory);
|
2018-04-03 12:59:07 +00:00
|
|
|
queue.callFunctionReturnFlushedQueue(name, 'dummy', []);
|
|
|
|
expect(queue.__shouldPauseOnThrow).toHaveBeenCalledTimes(2);
|
2017-12-11 15:59:45 +00:00
|
|
|
});
|
2016-06-13 15:23:23 +00:00
|
|
|
});
|