Skip to content

Commit 3d77c63

Browse files
committed
Improve coverage
Signed-off-by: Danny Kopping <danny@coder.com>
1 parent 73bac3f commit 3d77c63

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
A provisioning which appears to complete before it started has its start and end times aligned.
2+
3+
-- apply --
4+
{"@level":"info","@message":"coder_agent.main: Creating...","@module":"terraform.ui","@timestamp":"2024-08-15T10:26:39.616546+02:00","hook":{"resource":{"addr":"coder_agent.main","module":"","resource":"coder_agent.main","implied_provider":"coder","resource_type":"coder_agent","resource_name":"main","resource_key":null},"action":"create"},"type":"apply_start"}
5+
{"@level":"info","@message":"coder_agent.main: Creation complete after 0s [id=a23083da-4679-4396-a306-f7b466237883]","@module":"terraform.ui","@timestamp":"2024-08-15T10:21:39.618045+02:00","hook":{"resource":{"addr":"coder_agent.main","module":"","resource":"coder_agent.main","implied_provider":"coder","resource_type":"coder_agent","resource_name":"main","resource_key":null},"action":"create","id_key":"id","id_value":"a23083da-4679-4396-a306-f7b466237883","elapsed_seconds":0},"type":"apply_complete"}
6+
-- timings --
7+
{"start":"2024-08-15T08:21:39.618045Z","end":"2024-08-15T08:21:39.618045Z","action":"create","source":"coder","resource":"coder_agent.main","stage":"apply","state":"COMPLETED"}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
An apply_start without a corresponding apply_complete will not produce a timing (and vice-versa).
2+
3+
-- plan --
4+
{"@level":"info","@message":"data.coder_provisioner.me: Refreshing...","@module":"terraform.ui","@timestamp":"2024-08-15T10:26:39.194726+02:00","hook":{"resource":{"addr":"data.coder_provisioner.me","module":"","resource":"data.coder_provisioner.me","implied_provider":"coder","resource_type":"coder_provisioner","resource_name":"me","resource_key":null},"action":"read"},"type":"apply_start"}
5+
-- apply --
6+
{"@level":"info","@message":"coder_agent.main: Creation complete after 0s [id=a23083da-4679-4396-a306-f7b466237883]","@module":"terraform.ui","@timestamp":"2024-08-15T10:26:39.618045+02:00","hook":{"resource":{"addr":"coder_agent.main","module":"","resource":"coder_agent.main","implied_provider":"coder","resource_type":"coder_agent","resource_name":"main","resource_key":null},"action":"create","id_key":"id","id_value":"a23083da-4679-4396-a306-f7b466237883","elapsed_seconds":0},"type":"apply_complete"}
7+
-- timings --

provisioner/terraform/timings_internal_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ var (
2121
inputError []byte
2222
//go:embed testdata/timings-aggregation/complete.txtar
2323
inputComplete []byte
24+
//go:embed testdata/timings-aggregation/incomplete.txtar
25+
inputIncomplete []byte
26+
//go:embed testdata/timings-aggregation/faster-than-light.txtar
27+
inputFasterThanLight []byte
2428
)
2529

2630
func TestAggregation(t *testing.T) {
@@ -46,6 +50,14 @@ func TestAggregation(t *testing.T) {
4650
name: "complete",
4751
input: inputComplete,
4852
},
53+
{
54+
name: "incomplete",
55+
input: inputIncomplete,
56+
},
57+
{
58+
name: "faster-than-light",
59+
input: inputFasterThanLight,
60+
},
4961
}
5062

5163
// nolint:paralleltest // Not since go v1.22.
@@ -64,8 +76,11 @@ func TestAggregation(t *testing.T) {
6476
t.Logf("%s: %s", t.Name(), arc.Comment)
6577

6678
var actualTimings []*proto.Timing
79+
80+
// The last "file" MUST contain the expected timings.
6781
expectedTimings := arc.Files[len(arc.Files)-1]
6882

83+
// Iterate over the initial "files" and extract their timings according to their stage.
6984
for i := 0; i < len(arc.Files)-1; i++ {
7085
file := arc.Files[i]
7186
stage := database.ProvisionerJobTimingStage(file.Name)
@@ -77,6 +92,7 @@ func TestAggregation(t *testing.T) {
7792
actualTimings = append(actualTimings, agg.aggregate()...)
7893
}
7994

95+
// Ensure that the expected timings were produced.
8096
expected := ParseTimingLines(t, expectedTimings.Data)
8197
StableSortTimings(t, actualTimings) // To reduce flakiness.
8298
if !assert.True(t, TimingsAreEqual(t, expected, actualTimings)) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy