【问题标题】:Container STATE is Error when the Test Result has Failure测试结果失败时容器状态为错误
【发布时间】:2020-02-25 18:56:17
【问题描述】:

我已经使用 minikube 在本地设置了 Kubernetes 环境。我创建了一个包含 3 个容器的作业。

  • 集线器
  • 铬
  • 应用程序(Selenium-TestNG)

当我申请/创建工作时,它将设置 Hub/Chrome/App。执行硒测试。

如果所有测试都成功完成,您将看到如下所示的 Container 状态

来自 webAutomation1 应用程序的结果

上面的事情和预期的一样。在容器列表方面看起来不错

现在,如果我们已经完成了应用程序(执行测试),但出现了一些失败,如下所示

然后,我的容器列表将显示为错误

我现在使用 ITestListenr 将日志写入控制台。是什么让容器状态变成错误。?在容器和应用程序之间的集成方面有什么我看不到的吗?

如果有人帮我解决这个问题,我们将不胜感激。

【问题讨论】:

  • 我想当测试失败时返回码不是 0 从而导致 pod 中的退出码出错?

标签: selenium-webdriver kubernetes testng containers minikube


【解决方案1】:

根据TestNG exit codes:

当 TestNG 完成执行时,它会以返回码退出。这 可以检查返回代码以了解故障的性质 (如果有的话)。下表总结了不同的出口 TestNG 当前使用的代码。

/**
 * |---------------------|---------|--------|-------------|------------------------------------------|
 * | FailedWithinSuccess | Skipped | Failed | Status Code | Remarks                                  |
 * |---------------------|---------|--------|-------------|------------------------------------------|
 * | 0                   | 0       | 0      | 0           | Passed tests                             |
 * | 0                   | 0       | 1      | 1           | Failed tests                             |
 * | 0                   | 1       | 0      | 2           | Skipped tests                            |
 * | 0                   | 1       | 1      | 3           | Skipped/Failed tests                     |
 * | 1                   | 0       | 0      | 4           | FailedWithinSuccess tests                |
 * | 1                   | 0       | 1      | 5           | FailedWithinSuccess/Failed tests         |
 * | 1                   | 1       | 0      | 6           | FailedWithinSuccess/Skipped tests        |
 * | 1                   | 1       | 1      | 7           | FailedWithinSuccess/Skipped/Failed tests |
 * |---------------------|---------|--------|-------------|------------------------------------------|
 */

您的容器可能正在使用 TestNG 作为主进程,任何不被视为 Passed tests 的测试(即退出代码不同于 0)都会导致 Pod 处于终止/错误状态。

您可以通过Determining the Reason for Pod Failure确认。

例如:您可以检查您的 pod 状态;输出将是这样的:

$ kubectl get my-pod-name -o=json | jq .status.containerStatuses[].state
{
  "terminated": {
    "containerID": "docker://9bc2497ec0d2bc3b1b62483c217aaaaa1027102a5f7ff1688f47b94254",
    "exitCode": 1,
    "finishedAt": "2019-10-28T02:00:10Z",
    "reason": "Error",
    "startedAt": "2019-10-28T02:00:05Z"
  }
}

并检查退出代码是否与您的 TestNG 状态代码匹配。

【讨论】:

  • @Edurado,完美!我确实检查过。谢谢您的回答。它确实告诉我问题出在哪里。
  • 有没有办法我们总是向容器发送状态码 0?这样它就以完成状态结束了?
  • 您可以将|| true 附加到您的作业命令...
猜你喜欢
  • 2021-10-16
  • 1970-01-01
  • 2012-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-18
  • 1970-01-01
相关资源
最近更新 更多