Skip to content

Commit

Permalink
add comment and refactor waitForNode into setup script
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanRHall committed Mar 11, 2020
1 parent 0a33d25 commit c995a27
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions tools/ci-ts/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
preset: 'ts-jest',
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
testEnvironment: 'node',
testPathIgnorePatterns: ['/node_modules/', 'dist/'],
testRunner: 'jest-circus/runner',
Expand Down
7 changes: 7 additions & 0 deletions tools/ci-ts/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { getArgs, waitForService } from './test-helpers/common'

const { CHAINLINK_URL } = getArgs(['CHAINLINK_URL'])

beforeAll(async () => {
await waitForService(CHAINLINK_URL)
})
13 changes: 9 additions & 4 deletions tools/ci-ts/test-helpers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,18 @@ export async function wait(ms: number) {
})
}

/**
* Makes a simple get request to an endpoint and ensures the service responds.
* Status code doesn't matter - just ensures the service is running.
* @param endpoint the url of the service
* @param timeout the time to wait before erroring
*/
export async function waitForService(endpoint: string, timeout = 20000) {
await assertAsync(
async () => {
return fetch(endpoint)
async () =>
fetch(endpoint)
.then(() => true)
.catch(() => false)
},
.catch(() => false),
`${endpoint} is unreachable after ${timeout}ms`,
timeout,
)
Expand Down
7 changes: 1 addition & 6 deletions tools/ci-ts/tests/flux-monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
wait,
createProvider,
fundAddress,
waitForService,
} from '../test-helpers/common'
import * as clClient from '../test-helpers/chainlink-cli'
import { contract, helpers as h, matchers } from '@chainlink/test-helpers'
Expand All @@ -15,10 +14,7 @@ import { JobSpec } from '../../../operator_ui/@types/operator_ui'
import 'isomorphic-unfetch'
import { ethers } from 'ethers'

const { EXTERNAL_ADAPTER_URL, CHAINLINK_URL } = getArgs([
'EXTERNAL_ADAPTER_URL',
'CHAINLINK_URL',
])
const { EXTERNAL_ADAPTER_URL } = getArgs(['EXTERNAL_ADAPTER_URL'])

const provider = createProvider()
const carol = ethers.Wallet.createRandom().connect(provider)
Expand Down Expand Up @@ -61,7 +57,6 @@ describe('flux monitor eth client integration', () => {
let node1Address: string

beforeAll(async () => {
await waitForService(CHAINLINK_URL)
clClient.login()
node1Address = clClient.getAdminInfo()[0].address
await fundAddress(carol.address)
Expand Down

0 comments on commit c995a27

Please sign in to comment.