Add proxy method to verify whether it has a request in progress and to cancel active requests
MODIFY
lib/jsonwp-proxy/proxy.js
lib/jsonwp-proxy/proxy.js
@@ -9,7 +9,7 @@ import { errors } from '../mjsonwp/errors';
const log = logger.getLogger('JSONWP Proxy');
// TODO: Make this value configurable as a server side capability
const LOG_OBJ_LENGTH = 1024; // MAX LENGTH Logged to file / console
-const REQUEST_TIMEOUT = 240000;
+const DEFAULT_REQUEST_TIMEOUT = 240000;
class JWProxy {
constructor (opts = {}) {
@@ -19,15 +19,32 @@ class JWProxy {
port: 4444,
base: '/wd/hub',
sessionId: null,
- timeout: REQUEST_TIMEOUT,
+ timeout: DEFAULT_REQUEST_TIMEOUT,
}, opts);
this.scheme = this.scheme.toLowerCase();
+ this._activeRequests = [];
}
// abstract the call behind a member function
// so that we can mock it in tests
async request (...args) {
- return await request(...args);
+ const currentRequest = request(...args);
+ this._activeRequests.push(currentRequest);
+ return await currentRequest.finally(() => _.pull(this._activeRequests, currentRequest));
+ }
+
+ getActiveRequestsCount () {
+ return this._activeRequests.length;
+ }
+
+ cancelActiveRequests () {
+ try {
+ for (let r of this._activeRequests) {
+ r.cancel();
+ }
+ } finally {
+ this._activeRequests = [];
+ }
}
endpointRequiresSessionId (endpoint) {

Add proxy method to verify whether it has a request in progress and to cancel active requests (#105)