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', () => {
|
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) => {
|
Object.keys(ethereumRpc).sort().forEach((endpoint) => {
|
||||||
describe(endpoint, () => {
|
describe(endpoint, () => {
|
||||||
|
@ -25,7 +25,7 @@ import Api from '../api';
|
|||||||
import Contract from './contract';
|
import Contract from './contract';
|
||||||
import { isInstanceOf, isFunction } from '../util/types';
|
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);
|
const eth = new Api(transport);
|
||||||
|
|
||||||
describe('api/contract/Contract', () => {
|
describe('api/contract/Contract', () => {
|
||||||
|
@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
|
|||||||
import Http from '../../transport/http';
|
import Http from '../../transport/http';
|
||||||
import Db from './db';
|
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', () => {
|
describe('api/rpc/Db', () => {
|
||||||
let scope;
|
let scope;
|
||||||
|
@ -20,7 +20,7 @@ import { isBigNumber } from '../../../../test/types';
|
|||||||
import Http from '../../transport/http';
|
import Http from '../../transport/http';
|
||||||
import Eth from './eth';
|
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', () => {
|
describe('rpc/Eth', () => {
|
||||||
const address = '0x63Cf90D3f0410092FC0fca41846f596223979195';
|
const address = '0x63Cf90D3f0410092FC0fca41846f596223979195';
|
||||||
|
@ -20,7 +20,7 @@ import { isBigNumber } from '../../../../test/types';
|
|||||||
import Http from '../../transport/http';
|
import Http from '../../transport/http';
|
||||||
import Net from './net';
|
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('api/rpc/Net', () => {
|
||||||
describe('peerCount', () => {
|
describe('peerCount', () => {
|
||||||
|
@ -20,7 +20,7 @@ import { isBigNumber } from '../../../../test/types';
|
|||||||
import Http from '../../transport/http';
|
import Http from '../../transport/http';
|
||||||
import Parity from './parity';
|
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('api/rpc/parity', () => {
|
||||||
describe('accountsInfo', () => {
|
describe('accountsInfo', () => {
|
||||||
|
@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
|
|||||||
import Http from '../../transport/http';
|
import Http from '../../transport/http';
|
||||||
import Personal from './personal';
|
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', () => {
|
describe('rpc/Personal', () => {
|
||||||
const account = '0x63cf90d3f0410092fc0fca41846f596223979195';
|
const account = '0x63cf90d3f0410092fc0fca41846f596223979195';
|
||||||
|
@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
|
|||||||
import Http from '../../transport/http';
|
import Http from '../../transport/http';
|
||||||
import Trace from './trace';
|
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', () => {
|
describe('api/rpc/Trace', () => {
|
||||||
let scope;
|
let scope;
|
||||||
|
@ -19,7 +19,7 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
|
|||||||
import Http from '../../transport/http';
|
import Http from '../../transport/http';
|
||||||
import Web3 from './web3';
|
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', () => {
|
describe('api/rpc/Web3', () => {
|
||||||
let scope;
|
let scope;
|
||||||
|
@ -19,11 +19,14 @@ import JsonRpcBase from '../jsonRpcBase';
|
|||||||
|
|
||||||
/* global fetch */
|
/* global fetch */
|
||||||
export default class Http extends JsonRpcBase {
|
export default class Http extends JsonRpcBase {
|
||||||
constructor (url) {
|
constructor (url, connectTimeout = 1000) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this._connected = true;
|
this._connected = true;
|
||||||
this._url = url;
|
this._url = url;
|
||||||
|
this._connectTimeout = connectTimeout;
|
||||||
|
|
||||||
|
this._pollConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
_encodeOptions (method, params) {
|
_encodeOptions (method, params) {
|
||||||
@ -77,4 +80,17 @@ export default class Http extends JsonRpcBase {
|
|||||||
return response.result;
|
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 { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
|
||||||
import Http from './http';
|
import Http from './http';
|
||||||
|
|
||||||
const transport = new Http(TEST_HTTP_URL);
|
const transport = new Http(TEST_HTTP_URL, -1);
|
||||||
|
|
||||||
describe('api/transport/Http', () => {
|
describe('api/transport/Http', () => {
|
||||||
describe('instance', () => {
|
describe('instance', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user