From 5ba175e3c811244e8452546b600eab797def8924 Mon Sep 17 00:00:00 2001 From: dblock Date: Thu, 11 Jul 2024 09:40:15 -0400 Subject: [PATCH] Actively wait for cluster to come up and display version. Signed-off-by: dblock --- .cspell | 1 + .github/workflows/test-spec.yml | 6 +++--- tools/src/OpenSearchHttpClient.ts | 13 ++++++++++++- tools/src/tester/TestRunner.ts | 12 +++++++++++- tools/src/tester/test.ts | 2 +- tools/tests/tester/helpers.ts | 2 +- tools/tests/tester/test.test.ts | 4 ++-- 7 files changed, 31 insertions(+), 9 deletions(-) diff --git a/.cspell b/.cspell index e08fb3d21..c48ec6767 100644 --- a/.cspell +++ b/.cspell @@ -125,6 +125,7 @@ nysiis opendistro opensearch opensearchproject +opensearchstaging ords oversample performanceanalyzer diff --git a/.github/workflows/test-spec.yml b/.github/workflows/test-spec.yml index 59193b0af..152f71e22 100644 --- a/.github/workflows/test-spec.yml +++ b/.github/workflows/test-spec.yml @@ -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: @@ -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 \ No newline at end of file diff --git a/tools/src/OpenSearchHttpClient.ts b/tools/src/OpenSearchHttpClient.ts index 7ffcb1421..9d9a7f1a6 100644 --- a/tools/src/OpenSearchHttpClient.ts +++ b/tools/src/OpenSearchHttpClient.ts @@ -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 @@ -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 } diff --git a/tools/src/tester/TestRunner.ts b/tools/src/tester/TestRunner.ts index 87ac31c87..cfe286127 100644 --- a/tools/src/tester/TestRunner.ts +++ b/tools/src/tester/TestRunner.ts @@ -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 @@ -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) diff --git a/tools/src/tester/test.ts b/tools/src/tester/test.ts index 32039b234..9a9ee3c8a 100644 --- a/tools/src/tester/test.ts +++ b/tools/src/tester/test.ts @@ -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( diff --git a/tools/tests/tester/helpers.ts b/tools/tests/tester/helpers.ts index 748c21e3d..fb1217902 100644 --- a/tools/tests/tester/helpers.ts +++ b/tools/tests/tester/helpers.ts @@ -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, diff --git a/tools/tests/tester/test.test.ts b/tools/tests/tester/test.test.ts index e2b2ea330..df48dc196 100644 --- a/tools/tests/tester/test.test.ts +++ b/tools/tests/tester/test.test.ts @@ -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, ...)")}` ) })