Determine real-time HTTP connected status (#3335)
* Determine real-time HTTP connected status * Update failing tests, no polluting polling
This commit is contained in:
parent
7cc88b175f
commit
c7b99cd7e6
@ -34,7 +34,7 @@ describe('api/Api', () => {
|
||||
});
|
||||
|
||||
describe('interface', () => {
|
||||
const api = new Api(new Api.Transport.Http(TEST_HTTP_URL));
|
||||
const api = new Api(new Api.Transport.Http(TEST_HTTP_URL, -1));
|
||||
|
||||
Object.keys(ethereumRpc).sort().forEach((endpoint) => {
|
||||
describe(endpoint, () => {
|
||||
|
@ -25,7 +25,7 @@ import Api from '../api';
|
||||
import Contract from './contract';
|
||||
import { isInstanceOf, isFunction } from '../util/types';
|
||||
|
||||
const transport = new Api.Transport.Http(TEST_HTTP_URL);
|
||||
const transport = new Api.Transport.Http(TEST_HTTP_URL, -1);
|
||||
const eth = new Api(transport);
|
||||
|
||||
describe('api/contract/Contract', () => {
|
||||
|
@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
|
||||
import Http from '../../transport/http';
|
||||
import Db from './db';
|
||||
|
||||
const instance = new Db(new Http(TEST_HTTP_URL));
|
||||
const instance = new Db(new Http(TEST_HTTP_URL, -1));
|
||||
|
||||
describe('api/rpc/Db', () => {
|
||||
let scope;
|
||||
|
@ -20,7 +20,7 @@ import { isBigNumber } from '../../../../test/types';
|
||||
import Http from '../../transport/http';
|
||||
import Eth from './eth';
|
||||
|
||||
const instance = new Eth(new Http(TEST_HTTP_URL));
|
||||
const instance = new Eth(new Http(TEST_HTTP_URL, -1));
|
||||
|
||||
describe('rpc/Eth', () => {
|
||||
const address = '0x63Cf90D3f0410092FC0fca41846f596223979195';
|
||||
|
@ -20,7 +20,7 @@ import { isBigNumber } from '../../../../test/types';
|
||||
import Http from '../../transport/http';
|
||||
import Net from './net';
|
||||
|
||||
const instance = new Net(new Http(TEST_HTTP_URL));
|
||||
const instance = new Net(new Http(TEST_HTTP_URL, -1));
|
||||
|
||||
describe('api/rpc/Net', () => {
|
||||
describe('peerCount', () => {
|
||||
|
@ -20,7 +20,7 @@ import { isBigNumber } from '../../../../test/types';
|
||||
import Http from '../../transport/http';
|
||||
import Parity from './parity';
|
||||
|
||||
const instance = new Parity(new Http(TEST_HTTP_URL));
|
||||
const instance = new Parity(new Http(TEST_HTTP_URL, -1));
|
||||
|
||||
describe('api/rpc/parity', () => {
|
||||
describe('accountsInfo', () => {
|
||||
|
@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
|
||||
import Http from '../../transport/http';
|
||||
import Personal from './personal';
|
||||
|
||||
const instance = new Personal(new Http(TEST_HTTP_URL));
|
||||
const instance = new Personal(new Http(TEST_HTTP_URL, -1));
|
||||
|
||||
describe('rpc/Personal', () => {
|
||||
const account = '0x63cf90d3f0410092fc0fca41846f596223979195';
|
||||
|
@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
|
||||
import Http from '../../transport/http';
|
||||
import Trace from './trace';
|
||||
|
||||
const instance = new Trace(new Http(TEST_HTTP_URL));
|
||||
const instance = new Trace(new Http(TEST_HTTP_URL, -1));
|
||||
|
||||
describe('api/rpc/Trace', () => {
|
||||
let scope;
|
||||
|
@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
|
||||
import Http from '../../transport/http';
|
||||
import Web3 from './web3';
|
||||
|
||||
const instance = new Web3(new Http(TEST_HTTP_URL));
|
||||
const instance = new Web3(new Http(TEST_HTTP_URL, -1));
|
||||
|
||||
describe('api/rpc/Web3', () => {
|
||||
let scope;
|
||||
|
@ -19,11 +19,14 @@ import JsonRpcBase from '../jsonRpcBase';
|
||||
|
||||
/* global fetch */
|
||||
export default class Http extends JsonRpcBase {
|
||||
constructor (url) {
|
||||
constructor (url, connectTimeout = 1000) {
|
||||
super();
|
||||
|
||||
this._connected = true;
|
||||
this._url = url;
|
||||
this._connectTimeout = connectTimeout;
|
||||
|
||||
this._pollConnection();
|
||||
}
|
||||
|
||||
_encodeOptions (method, params) {
|
||||
@ -77,4 +80,17 @@ export default class Http extends JsonRpcBase {
|
||||
return response.result;
|
||||
});
|
||||
}
|
||||
|
||||
_pollConnection = () => {
|
||||
if (this._connectTimeout <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nextTimeout = () => setTimeout(this._pollConnection, this._connectTimeout);
|
||||
|
||||
this
|
||||
.execute('net_listening')
|
||||
.then(nextTimeout)
|
||||
.catch(nextTimeout);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
|
||||
import Http from './http';
|
||||
|
||||
const transport = new Http(TEST_HTTP_URL);
|
||||
const transport = new Http(TEST_HTTP_URL, -1);
|
||||
|
||||
describe('api/transport/Http', () => {
|
||||
describe('instance', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user