microcks test exits with code 1 (contract failure) instead of code 11 (connection) when polling loop times out
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
cmd/testExecutor.go の runTestAndWait から着手する。ポーリングループは inProgress がまだ true のまま抜けてしまい nil エラーを返すため、cmd/test.go はそれを errors.ErrTestFailed として扱い、cmd/exit.go はそれを終了コード 1 にマッピングする。ループ後の inProgress チェックを追加してタイムアウトエラーを errors.KindConnection でラップし、その後 issue 記載の Python モックサーバーと go run main.go test ... --waitFor=100milli を使って、CLI が 1 の代わりに 11 で終了することを確認する。期待されるコードは documentation/error-handling.md と突き合わせ、既存の Go テストを実行する。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
While going through the changes in PR #540 and the new documentation/error-handling.md, I noticed a gap in how the test polling loop handles timeouts.
In cmd/testExecutor.go, runTestAndWait polls the server in a loop until the test finishes or the deadline passes:
for nowInMilliseconds() < future {
testResultSummary, err := mc.GetTestResult(testResultID)
if err != nil {
return false, "", fmt.Errorf("checking test result: %w", err)
}
success = testResultSummary.Success
inProgress := testResultSummary.InProgress
if !inProgress {
break
}
time.Sleep(2 * time.Second)
}
return success, testResultID, nil
If the server hasn't finished by the time the deadline runs out, the loop exits with inProgress still true, but the function returns nil for the error. No timeout is ever flagged.
Back in cmd/test.go, the caller sees err == nil and !success, so it returns errors.ErrTestFailed:
success, testResultID, err := runTestAndWait(mc, params)
if err != nil {
return err
}
if !success {
return errors.ErrTestFailed // exit code 1
}
And cmd/exit.go maps that to exit code 1:
case stderrors.Is(err, errors.ErrTestFailed):
// A clean run with a non-conforming result — pytest-style exit 1.
return 1
The problem is that a polling timeout is not a contract conformance failure, it's an infrastructure/connection issue. According to error-handling.md, exit code 1 is strictly for "a clean run whose result did not conform". A timeout means the CLI never got a final result at all.
Expected behavior
When the polling loop runs out of time with inProgress still true, it should return a proper timeout error wrapped as KindConnection, something like:
if inProgress {
return false, testResultID, errors.Wrap(errors.KindConnection,
fmt.Errorf("test polling timed out after %dms waiting for result %s",
params.waitForMillis+10000, testResultID))
}
This would cause ExitCodeFor to return 11 and Handle to print a clear error to stderr, so CI/CD pipelines can tell apart "API contract broken" (exit 1) from "server was too slow or unreachable" (exit 11).
Actual behavior
MicrocksClient got status for test "test-hanging-1" - success: false, inProgress: true
MicrocksTester waiting for 2 seconds before checking again or exiting.
MicrocksClient got status for test "test-hanging-1" - success: false, inProgress: true
MicrocksTester waiting for 2 seconds before checking again or exiting.
... repeats until deadline ...
Test test-hanging-1: FAILURE (0ms)
Full TestResult details are available here: http://127.0.0.1:8888/#/tests/test-hanging-1
exit status 1
$ echo $?
1
The CLI exits with code 1 and falsely reports a contract test failure (FAILURE 0ms), with no error indicating that the run actually timed out.
How to Reproduce?
- Start a mock server simulating a test that remains in progress:
python3 -c '
from http.server import HTTPServer, BaseHTTPRequestHandler
class MockServer(BaseHTTPRequestHandler):
def do_POST(self):
self.send_response(201)
self.send_header("Content-Type", "application/json")
self.end_headers()
self.wfile.write(b"{\"id\":\"test-hanging-1\"}")
def do_GET(self):
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.end_headers()
self.wfile.write(b"{\"id\":\"test-hanging-1\",\"success\":false,\"inProgress\":true}")
def log_message(self, *args): pass
HTTPServer(("127.0.0.1", 8888), MockServer).serve_forever()
'
-
Run the test command with a short wait deadline:
go run main.go test "MyAPI:1.0" "http://localhost:8080" HTTP --microcksURL=http://127.0.0.1:8888 --waitFor=100milli -
Check the exit status: It returns 1 instead of 11.
Root cause: in cmd/testExecutor.go (lines 76–103), the loop ends when nowInMilliseconds() >= future, but falls through to return success, testResultID, nil without verifying if inProgress was still true.
Microcks version or git rev
main
Install method (docker-compose, helm chart, operator, docker-desktop extension,...)
CLI
Additional information
The fix is small and self-contained, only cmd/testExecutor.go needs to change (add a post-loop inProgress check). All three callers of runTestAndWait (cmd/test.go, and two places in cmd/testDryRun.go) already have if err != nil { return err } guards, so they'll handle the new error correctly without any changes.
- 主要言語
- Go
- スター
- 57
- フォーク
- 73
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 28
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microcks/microcks-cli のほかの issue
-
Default configuration path falls back to the current directory when the home directory cannot be determined対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
microcks/microcks-cli#583 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug: YAML parse error in config is silently swallowed, login overwrites all other contexts対応中かも @Sarthak-Shreshtha01 が 5 日前に担当しました。 オープンcomponent/cli kind/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
microcks/microcks-cli#572 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
import-dir uploads secondary artifacts before their primary API definition対応中かも @doraem-on が 12 日前に担当しました。 オープンcomponent/cli kind/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
microcks/microcks-cli#561 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
TEST: `ConnectAndGetToken` Returns Error on Non-200 Response対応中かも @aniket866 が 15 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
microcks/microcks-cli#554 ·
メンテナーはふだん 1 日以内に返信
-
Empty `AuthToken` Causes Cryptic JWT Parse Error対応中かも @aniket866 が 15 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
microcks/microcks-cli#551 ·
メンテナーはふだん 1 日以内に返信
microcks/microcks-cli の issue をすべて見る
似ている issue
-
Action Required: Fix Renovate Configuration対応中かも @thompson-tomo が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
open-telemetry/opentelemetry-collector#16170 ·
メンテナーはふだん 1 日以内に返信
-
automation awf compiler specifications
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
state:triage-needed
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
puppe1990/amarra-cais#342 ·
メンテナーはふだん 1 日以内に返信
-
replay: a run cancelled during environment setup is logged as an ERROR (Instrument drops the cancellation)対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信