Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] npm run test requires a docker instance of OpenSearch #313

Closed
dblock opened this issue Jun 4, 2024 · 3 comments · Fixed by #320
Closed

[BUG] npm run test requires a docker instance of OpenSearch #313

dblock opened this issue Jun 4, 2024 · 3 comments · Fixed by #320
Labels
bug Something isn't working

Comments

@dblock
Copy link
Member

dblock commented Jun 4, 2024

What is the bug?

Tests require a local OpenSearch running on 9200. This is unexpected for unit tests.

How can one reproduce the bug?

$ npm run test -- tools/tests/tester/TestsRunner.test.ts 

> [email protected] test
> jest tools/tests/tester/TestsRunner.test.ts

 FAIL  tools/tests/tester/TestsRunner.test.ts
  ✕ stories folder (134 ms)

  ● stories folder

    connect ECONNREFUSED ::1:9200

      26 |     const response: Record<string, any> = {}
      27 |     const [url, params] = this.#parse_url(chapter.path, chapter.parameters ?? {})
    > 28 |     await axios.request({
         |     ^
      29 |       url,
      30 |       auth: {
      31 |         username: 'admin',

      at Function.Object.<anonymous>.AxiosError.from (node_modules/axios/lib/core/AxiosError.js:89:14)
      at RedirectableRequest.handleRequestError (node_modules/axios/lib/adapters/http.js:610:25)
      at ClientRequest.eventHandlers.<computed> (node_modules/follow-redirects/index.js:38:24)
      at Axios.request (node_modules/axios/lib/core/Axios.js:45:41)
      at ChapterReader.read (tools/src/tester/ChapterReader.ts:28:5)
      at ChapterEvaluator.evaluate (tools/src/tester/ChapterEvaluator.ts:35:22)
      at StoryEvaluator.#evaluate_chapters (tools/src/tester/StoryEvaluator.ts:71:28)
      at StoryEvaluator.evaluate (tools/src/tester/StoryEvaluator.ts:50:22)
      at TestsRunner.run (tools/src/tester/TestsRunner.ts:45:26)
      at Object.<anonymous> (tools/tests/tester/TestsRunner.test.ts:20:30)

    Cause:
    connect ECONNREFUSED ::1:9200



Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        1.42 s, estimated 2 s

What is the expected behavior?

Tests run by default should not require a server.

Do you have any additional context?

We can move some tests to integration tests, use mocks, or the new --dry-run option added in #303.

Running all tests fails with unhelpful errors.

node:internal/child_process/serialization:159
    const string = JSONStringify(message) + '\n';
                   ^

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property '_httpMessage' -> object with constructor 'Object'
    --- property 'socket' closes the circle
    at stringify (<anonymous>)
    at writeChannelMessage (node:internal/child_process/serialization:159:20)
    at process.target._send (node:internal/child_process:838:17)
    at process.target.send (node:internal/child_process:738:19)
    at reportSuccess (/Users/dblock/source/opensearch-project/opensearch-api-specification/dblock-opensearch-api-specification/node_modules/jest-worker/build/workers/processChild.js:82:11)

@nhtruong
Copy link
Collaborator

nhtruong commented Jun 5, 2024

The weird error message comes from Jest. I got the exact same error previously when trying to run the integ tests for the spec test framework without a docker container running. Instead of an AXIOS error being printed out (as it does when you run npm run test:spec), Jest obfuscates that error and throws TypeError: Converting circular structure to JSON instead because the AXIOS error object has cyclic references among its properties.

@nhtruong
Copy link
Collaborator

nhtruong commented Jun 5, 2024

tools/tests/tester/TestsRunner.test.ts is actually an integ test tho?

@dblock
Copy link
Member Author

dblock commented Jun 5, 2024

@nhtruong I think one idea would be to split npm run test into npm run test:unit and npm run test:integration and run only unit tests by default in npm run test. I just don't know how best to do that yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants