Skip to content

Commit

Permalink
cli: refactor tests setup, fix bug in indexing-rules test
Browse files Browse the repository at this point in the history
The test IndexerManagementClient was being instantiated before each
individual test, resulting in significant loss of peformance and
unpredictable behavior during tests.
  • Loading branch information
tilacog committed Jul 21, 2023
1 parent 48b104b commit ee3d6ad
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
7 changes: 5 additions & 2 deletions packages/indexer-cli/src/__tests__/indexer/cost.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { cliTest, setup, teardown } from '../util'
import { cliTest, setup, seed, teardown } from '../util'
import path from 'path'

const baseDir = path.join(__dirname, '..')

describe('Indexer cost tests', () => {
describe('With indexer management server', () => {
beforeEach(setup)
beforeEach(async () => {
await setup()
await seed()
})
afterEach(teardown)
describe('Cost help', () => {
cliTest('Indexer cost', ['indexer', 'cost'], 'references/indexer-cost', {
Expand Down
12 changes: 8 additions & 4 deletions packages/indexer-cli/src/__tests__/indexer/rules.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { cliTest, setup, teardown } from '../util'
import { cliTest, setup, seed, teardown, deleteFromAllTables } from '../util'
import path from 'path'

const baseDir = path.join(__dirname, '..')

describe('Indexer rules tests', () => {
describe('With indexer management server', () => {
beforeEach(setup)
afterEach(teardown)
beforeAll(setup)
beforeEach(async () => {
await deleteFromAllTables()
await seed()
})
afterAll(teardown)
describe('Rules help', () => {
cliTest(
'Indexer rules',
Expand Down Expand Up @@ -509,7 +513,7 @@ describe('Indexer rules tests', () => {
cliTest(
'Indexer rules set - no args',
['indexer', 'rules', 'set'],
'references/indexer-rules-command-no-args',
'references/indexer-rules-no-network',
{
expectedExitCode: 1,
cwd: baseDir,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Deleted indexing rules for "QmZfeJYR86UARzp9HiXbURWunYgC9ywvPvoePNbuaATrEK" (deployment)
Deleted indexing rules for "QmZfeJYR86UARzp9HiXbURWunYgC9ywvPvoePNbuaATrEK" (deployment) on network: 'goerli'
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Deleted indexing rules for "QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr" (deployment)
Deleted indexing rules for "QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr" (deployment) on network: 'goerli'
10 changes: 9 additions & 1 deletion packages/indexer-cli/src/__tests__/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ export const setup = async () => {
process.setMaxListeners(100)
process.on('SIGTERM', shutdownIndexerManagementServer)
process.on('SIGINT', shutdownIndexerManagementServer)
}

// Set global, deployment, and subgraph based test rules and cost model
// Set global, deployment, and subgraph based test rules and cost model
export const seed = async () => {
const commands: string[][] = [
['indexer', 'connect', 'http://localhost:18000'],
[
Expand Down Expand Up @@ -263,6 +265,12 @@ export const teardown = async () => {
await dropSequelizeModels()
}

export const deleteFromAllTables = async () => {
const queryInterface = sequelize.getQueryInterface()
const allTables = await queryInterface.showAllTables()
await Promise.all(allTables.map(tableName => queryInterface.bulkDelete(tableName, {})))
}

export interface CommandResult {
exitCode: number | null
stdout: string | undefined
Expand Down
4 changes: 2 additions & 2 deletions packages/indexer-cli/src/commands/indexer/rules/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import chalk from 'chalk'
import { loadValidatedConfig } from '../../../config'
import { createIndexerManagementClient } from '../../../client'
import {
extractProtocolNetworkOption,
requireProtocolNetworkOption,
fixParameters,
parseOutputFormat,
} from '../../../command-helpers'
Expand Down Expand Up @@ -44,7 +44,7 @@ module.exports = {
const config = loadValidatedConfig()

try {
const protocolNetwork = extractProtocolNetworkOption(parameters.options)
const protocolNetwork = requireProtocolNetworkOption(parameters.options)
const [identifier, identifierType] = await processIdentifier(id, {
all: true,
global: true,
Expand Down

0 comments on commit ee3d6ad

Please sign in to comment.