Skip to content

Commit

Permalink
Actively wait for cluster to come up and display version.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Jul 11, 2024
1 parent 07950a8 commit 5ba175e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions .cspell
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ nysiis
opendistro
opensearch
opensearchproject
opensearchstaging
ords
oversample
performanceanalyzer
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
strategy:
matrix:
entry:
- { version: 2.15.0, hub: 'opensearchproject' }
- { version: 2.16.0, hub: 'opensearchstaging' }
- {version: 2.15.0, hub: 'opensearchproject'}
- {version: 2.16.0, hub: 'opensearchstaging'}
name: test-opensearch-spec (version=${{ matrix.entry.version }}, hub=${{ matrix.entry.hub }})
runs-on: ubuntu-latest
env:
Expand All @@ -43,7 +43,7 @@ jobs:

- name: Run OpenSearch Cluster
working-directory: .github/opensearch-cluster
run: docker-compose up -d && sleep 60
run: docker-compose up -d

- name: Run Tests
run: npm run test:spec -- --opensearch-insecure
13 changes: 12 additions & 1 deletion tools/src/OpenSearchHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ export interface OpenSearchInfo {

export class OpenSearchHttpClient {
private readonly _axios: AxiosInstance
private readonly _opts?: OpenSearchHttpClientOptions

constructor (opts?: OpenSearchHttpClientOptions) {
this._opts = opts
this._axios = axios.create({
baseURL: opts?.url ?? DEFAULT_URL,
auth: opts?.username !== undefined && opts.password !== undefined
Expand All @@ -92,8 +94,17 @@ export class OpenSearchHttpClient {
attempt += 1
try {
const info = await this.get('/')
return info.data
if (this._opts?.responseType == 'arraybuffer') {
return JSON.parse(info.data as string)
} else {
return info.data
}
} catch (e) {
if (axios.isAxiosError(e)) {
if (e.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE') {
throw e
}
}
if (attempt >= max_attempts) {
throw e
}
Expand Down
12 changes: 11 additions & 1 deletion tools/src/tester/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ import { Result, type StoryEvaluation } from './types/eval.types'
import { type ResultLogger } from './ResultLogger'
import { basename, resolve } from 'path'
import type StoryValidator from "./StoryValidator";
import { OpenSearchHttpClient } from 'OpenSearchHttpClient'
import * as ansi from './Ansi'

export default class TestRunner {
private readonly _http_client: OpenSearchHttpClient
private readonly _story_validator: StoryValidator
private readonly _story_evaluator: StoryEvaluator
private readonly _result_logger: ResultLogger

constructor (story_validator: StoryValidator, story_evaluator: StoryEvaluator, result_logger: ResultLogger) {
constructor (http_client: OpenSearchHttpClient, story_validator: StoryValidator, story_evaluator: StoryEvaluator, result_logger: ResultLogger) {
this._http_client = http_client
this._story_validator = story_validator
this._story_evaluator = story_evaluator
this._result_logger = result_logger
Expand All @@ -32,6 +36,12 @@ export default class TestRunner {
let failed = false
const story_files = this.#sort_story_files(this.#collect_story_files(resolve(story_path), '', ''))
const evaluations: StoryEvaluation[] = []

if (!dry_run) {
const info = await this._http_client.wait_until_available()
console.log(`OpenSearch ${ansi.green(info.version.number)}\n`)
}

for (const story_file of story_files) {
const evaluation = this._story_validator.validate(story_file) ?? await this._story_evaluator.evaluate(story_file, dry_run)
evaluations.push(evaluation)
Expand Down
2 changes: 1 addition & 1 deletion tools/src/tester/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const supplemental_chapter_evaluator = new SupplementalChapterEvaluator(chapter_
const story_validator = new StoryValidator()
const story_evaluator = new StoryEvaluator(chapter_evaluator, supplemental_chapter_evaluator)
const result_logger = new ConsoleResultLogger(opts.tabWidth, opts.verbose)
const runner = new TestRunner(story_validator, story_evaluator, result_logger)
const runner = new TestRunner(http_client, story_validator, story_evaluator, result_logger)

runner.run(opts.testsPath, opts.dryRun)
.then(
Expand Down
2 changes: 1 addition & 1 deletion tools/tests/tester/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function construct_tester_components (spec_path: string): {
const story_validator = new StoryValidator()
const story_evaluator = new StoryEvaluator(chapter_evaluator, supplemental_chapter_evaluator)
const result_logger = new NoOpResultLogger()
const test_runner = new TestRunner(story_validator, story_evaluator, result_logger)
const test_runner = new TestRunner(opensearch_http_client, story_validator, story_evaluator, result_logger)
return {
specification,
operation_locator,
Expand Down
4 changes: 2 additions & 2 deletions tools/tests/tester/test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ test('--invalid', () => {
})

test('displays story filename', () => {
expect(spec(['--tests', 'tools/tests/tester/fixtures/empty_story']).stdout).toContain(
expect(spec(['--dry-run', '--tests', 'tools/tests/tester/fixtures/empty_story']).stdout).toContain(
`${ansi.green('PASSED ')} ${ansi.cyan(ansi.b('empty.yaml'))}`
)
})

test('invalid story', () => {
expect(spec(['--tests', 'tools/tests/tester/fixtures/invalid_story.yaml']).stdout).toContain(
expect(spec(['--dry-run', '--tests', 'tools/tests/tester/fixtures/invalid_story.yaml']).stdout).toContain(
`${ansi.gray("(Invalid Story: data/epilogues/0 must NOT have unevaluated properties, ...)")}`
)
})
Expand Down

0 comments on commit 5ba175e

Please sign in to comment.