dtufl26404 2019-04-18 09:50
浏览 79

将SIGTERM发送到Ginkgo测试套件时为假阳性

While writing tests using Ginkgo framework I noticed, that pressing C-c to terminate a running suite generates false positive.

note the green "1 Passed"

When you look at the code you will notice this test should fail after 5 seconds. When I terminate it after 2 seconds, the suite fails, but in the results, there is 1 passed test and 0 failed.

Same behavior for go versions 1.11.4 and 1.12.4 on Debian Stretch and Ubuntu 18.04.

Suite code (autogenerated using ginkgo bootstrap):

package hmmm_test

import (
    "testing"

    . "github.com/onsi/ginkgo"
    . "github.com/onsi/gomega"
)

func TestHmmm(t *testing.T) {
    RegisterFailHandler(Fail)
    RunSpecs(t, "Hmmm Suite")
}

Test code:

package hmmm_test

import (
    "time"

    . "github.com/onsi/ginkgo"
    . "github.com/onsi/gomega"
)

var _ = Describe("Hmmm", func() {
    Context("Dummy test", func() {
        It("should fail after 5 seconds", func() {
            time.Sleep(5 * time.Second)
            Expect(1).NotTo(Equal(1))
        })
    })
})

Output when the test runs for 5 seconds (correct one):

$ ginkgo

Running Suite: Hmmm Suite
=========================
Random Seed: 1555580607
Will run 1 of 1 specs
• Failure [5.001 seconds]
Hmmm
/tmp/hmmm/hmmm_test.go:10
  Dummy test
  /tmp/hmmm/hmmm_test.go:11
    should fail after 5 seconds [It]
    /tmp/hmmm/hmmm_test.go:12
    Expected
        <int>: 1
    not to equal
        <int>: 1
    /tmp/hmmm/hmmm_test.go:14
------------------------------
Summarizing 1 Failure:
[Fail] Hmmm Dummy test [It] should fail after 5 seconds
/tmp/hmmm/hmmm_test.go:14
Ran 1 of 1 Specs in 5.002 seconds
FAIL! -- 0 Passed | 1 Failed | 0 Pending | 0 Skipped
--- FAIL: TestHmmm (5.00s)
FAIL
Ginkgo ran 1 suite in 5.665592703s
Test Suite Failed

Output when the test is terminated before it finishes (false positive):

$ ginkgo

Running Suite: Hmmm Suite
=========================
Random Seed: 1555580763
Will run 1 of 1 specs
^C
Ran 1 of 1 Specs in 1.187 seconds
FAIL! -- 1 Passed | 0 Failed | 0 Pending | 0 Skipped
Ginkgo ran 1 suite in 1.85541211s
Test Suite Failed

I expect the output to be something like: FAIL! -- 0 Passed | 1 Failed | 0 Pending | 0 Skipped Or 1 skipped or pending, but not Passed especially that the test is written to fail.

Actual output suggests failure, but also that all tests... passed: FAIL! -- 1 Passed | 0 Failed | 0 Pending | 0 Skipped

Am I missing something?

  • 写回答

1条回答 默认 最新

  • dqpc1845 2019-04-18 14:34
    关注

    This is expected behaviour, but I wouldn't necessarily claim it was intentional, clear or correct. This occurs because tests start their running lifecycle as passing1 and change states on other events (failure/panic).

    When Ginkgo receives a SIGTERM it won't stop the currently running test (though it will prevent any more tests from running2). In parallel, it will collect a report for the tests that have run so far3. This collection will iterate over any nodes that have begun "processing"4 (loosely correlated with but starting slightly earlier than running). As the test started in a passed state and that has not changed, it is reported as passed.

    This question is not the place to discuss the validity of this approach (and there may well be a better one). Please use the issue that you opened if you would like to request a change to this behaviour5.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题