add DEBUG_NETWORK_SEND_DELAY for simulating slow network
Summary: It can be a pain to debug slow network issues, especially with the iOS simulator which doesn't have a network link conditioner. This makes it really easy and predictable by simply adding a `setTimeout` around calling `sendRequest`. Changelog: [General] [Added] - DEBUG_NETWORK_SEND_DELAY can be used to simulate slow network. Reviewed By: PeteTheHeat Differential Revision: D19236911 fbshipit-source-id: 14762c7e0c6408a8364aa569c482729a7a1fe740
This commit is contained in:
Родитель
674b591809
Коммит
4aac019176
|
@ -18,6 +18,8 @@ const base64 = require('base64-js');
|
|||
const invariant = require('invariant');
|
||||
const warning = require('fbjs/lib/warning');
|
||||
|
||||
const DEBUG_NETWORK_SEND_DELAY: false = false; // Set to a number of milliseconds when debugging
|
||||
|
||||
export type NativeResponseType = 'base64' | 'blob' | 'text';
|
||||
export type ResponseType =
|
||||
| ''
|
||||
|
@ -511,22 +513,29 @@ class XMLHttpRequest extends (EventTarget(...XHR_EVENTS): any) {
|
|||
nativeResponseType = 'blob';
|
||||
}
|
||||
|
||||
invariant(this._method, 'Request method needs to be defined.');
|
||||
invariant(this._url, 'Request URL needs to be defined.');
|
||||
RCTNetworking.sendRequest(
|
||||
this._method,
|
||||
this._trackingName,
|
||||
this._url,
|
||||
this._headers,
|
||||
data,
|
||||
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
|
||||
* when making Flow check .android.js files. */
|
||||
nativeResponseType,
|
||||
incrementalEvents,
|
||||
this.timeout,
|
||||
this.__didCreateRequest.bind(this),
|
||||
this.withCredentials,
|
||||
);
|
||||
const doSend = () => {
|
||||
invariant(this._method, 'Request method needs to be defined.');
|
||||
invariant(this._url, 'Request URL needs to be defined.');
|
||||
RCTNetworking.sendRequest(
|
||||
this._method,
|
||||
this._trackingName,
|
||||
this._url,
|
||||
this._headers,
|
||||
data,
|
||||
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
|
||||
* when making Flow check .android.js files. */
|
||||
nativeResponseType,
|
||||
incrementalEvents,
|
||||
this.timeout,
|
||||
this.__didCreateRequest.bind(this),
|
||||
this.withCredentials,
|
||||
);
|
||||
};
|
||||
if (DEBUG_NETWORK_SEND_DELAY) {
|
||||
setTimeout(doSend, DEBUG_NETWORK_SEND_DELAY);
|
||||
} else {
|
||||
doSend();
|
||||
}
|
||||
}
|
||||
|
||||
abort(): void {
|
||||
|
|
Загрузка…
Ссылка в новой задаче