Bug 2188193 - grafana-9.0.9-2 FTBFS due to erroneous test using date in the past
Summary: grafana-9.0.9-2 FTBFS due to erroneous test using date in the past
Keywords:
Status: VERIFIED
Alias: None
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: grafana
Version: CentOS Stream
Hardware: All
OS: Linux
unspecified
low
Target Milestone: rc
: ---
Assignee: Grafana Maintenance
QA Contact: Jan Kurik
Jacob Taylor Valdez
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-04-20 03:50 UTC by Neil Hanlon
Modified: 2023-07-19 23:12 UTC (History)
6 users (show)

Fixed In Version: grafana-9.2.10-3.el9
Doc Type: No Doc Update
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
0011-v9.0.x-Alerting-Fix-integration-test-for-creating-silences.patch (906 bytes, patch)
2023-04-20 03:56 UTC, Neil Hanlon
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-155261 0 None None None 2023-04-20 03:53:07 UTC

Description Neil Hanlon 2023-04-20 03:50:40 UTC
Description of problem: fails three tests due to a hard-coded date used as the end date of alerts created inside the tests.

https://github.com/grafana/grafana/pull/65722

Version-Release number of selected component (if applicable): 9.0.9-2

How reproducible: always

Steps to Reproduce:

1. Rebuild grafana-9.0.9-2 against current build root with tests enabled
2. Review rpmbuild failure due to building after March 31, 2023.

Actual results:

Tests fail unexpectedly

Expected results:

Tests complete successfully

Additional info:

Originally, the error will look like this, obscuring the error.

```
--- FAIL: TestAMConfigAccess (0.40s)
    testinfra.go:31: Grafana is listening on 127.0.0.1:41275
    --- FAIL: TestAMConfigAccess/when_creating_silence (0.03s)
        --- FAIL: TestAMConfigAccess/when_creating_silence/editor_request_should_succeed (0.01s)
            api_alertmanager_test.go:264: 
                	Error Trace:	api_alertmanager_test.go:264
                	Error:      	Not equal: 
                	            	expected: 202
                	            	actual  : 400
                	Test:       	TestAMConfigAccess/when_creating_silence/editor_request_should_succeed
        --- FAIL: TestAMConfigAccess/when_creating_silence/admin_request_should_succeed (0.01s)
            api_alertmanager_test.go:264: 
                	Error Trace:	api_alertmanager_test.go:264
                	Error:      	Not equal: 
                	            	expected: 202
                	            	actual  : 400
                	Test:       	TestAMConfigAccess/when_creating_silence/admin_request_should_succeed
    api_alertmanager_test.go:325: 
        	Error Trace:	api_alertmanager_test.go:325
        	Error:      	"[]" should have 2 item(s), but has 0
        	Test:       	TestAMConfigAccess
    --- FAIL: TestAMConfigAccess/when_deleting_a_silence (0.00s)
        --- FAIL: TestAMConfigAccess/when_deleting_a_silence/un-authenticated_request_should_fail (0.00s)
panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0
goroutine 3163 [running]:
testing.tRunner.func1.2({0x3174960, 0xc0022fb650})
	/usr/lib/golang/src/testing/testing.go:1396 +0x24e
testing.tRunner.func1()
	/usr/lib/golang/src/testing/testing.go:1399 +0x39f
panic({0x3174960, 0xc0022fb650})
	/usr/lib/golang/src/runtime/panic.go:884 +0x212
github.com/grafana/grafana/pkg/tests/api/alerting.TestAMConfigAccess.func5.1(0xc003cb1520)
	/builddir/build/BUILD/grafana-9.0.9/pkg/tests/api/alerting/api_alertmanager_test.go:362 +0x3d7
testing.tRunner(0xc003cb1520, 0xc003cc1440)
	/usr/lib/golang/src/testing/testing.go:1446 +0x10b
created by testing.(*T).Run
	/usr/lib/golang/src/testing/testing.go:1493 +0x35f
FAIL	github.com/grafana/grafana/pkg/tests/api/alerting	34.904s
```

Upon patching the test to fail on the response body instead, we observe the actual error which was obscured by the test's evaluation of the response code before response body.

```
--- FAIL: TestAMConfigAccess (0.30s)
    testinfra.go:31: Grafana is listening on 127.0.0.1:35835
    --- FAIL: TestAMConfigAccess/when_creating_silence (0.03s)
        --- FAIL: TestAMConfigAccess/when_creating_silence/editor_request_should_succeed (0.01s)
            api_alertmanager_test.go:270: 
                    Error Trace:    api_alertmanager_test.go:270
                    Error:          "{\"message\":\"end time can't be in the past: unable to create silence\",\"traceID\":\"00000000000000000000000000000000\"}" does not contain "{\"id\":\"0\",\"message\":\"silence created\"}"
                    Test:           TestAMConfigAccess/when_creating_silence/editor_request_should_succeed
        --- FAIL: TestAMConfigAccess/when_creating_silence/admin_request_should_succeed (0.01s)
            api_alertmanager_test.go:270: 
                    Error Trace:    api_alertmanager_test.go:270
                    Error:          "{\"message\":\"end time can't be in the past: unable to create silence\",\"traceID\":\"00000000000000000000000000000000\"}" does not contain "{\"id\":\"0\",\"message\":\"silence created\"}"
                    Test:           TestAMConfigAccess/when_creating_silence/admin_request_should_succeed
    api_alertmanager_test.go:325: 
            Error Trace:    api_alertmanager_test.go:325
            Error:          "[]" should have 2 item(s), but has 0
            Test:           TestAMConfigAccess
    --- FAIL: TestAMConfigAccess/when_deleting_a_silence (0.00s)
        --- FAIL: TestAMConfigAccess/when_deleting_a_silence/un-authenticated_request_should_fail (0.00s)
panic: runtime error: index out of range [0] with length 0 [recovered]
    panic: runtime error: index out of range [0] with length 0
```

Comment 1 Neil Hanlon 2023-04-20 03:56:39 UTC
Created attachment 1958449 [details]
0011-v9.0.x-Alerting-Fix-integration-test-for-creating-silences.patch

Comment 2 Stan Cox 2023-04-25 16:13:37 UTC
Came across this as well.  Thanks for the patch.

Comment 3 Neil Hanlon 2023-04-25 16:15:34 UTC
(In reply to Stan Cox from comment #2)
> Came across this as well.  Thanks for the patch.

Of course, happy to help. I did open an MR for Stream here: https://gitlab.com/redhat/centos-stream/rpms/grafana/-/merge_requests/21


Note You need to log in before you can comment on or make changes to this bug.