Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add test time measurements #3411

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft

Conversation

sfc-gh-jcieslak
Copy link
Collaborator

@sfc-gh-jcieslak sfc-gh-jcieslak commented Feb 24, 2025

Changes

  • Add a set of tools to measure test times and print the summary at the end

Tests

  • The solution was already tested on unit and integration tests and seems to be working correctly. The only limitation is that sub-tests are separated by / sign which shouldn't be used in any test name (I checked that none of our test is using it, so we should be fine).

Next steps

  • Adjust all the tests to include the measureTest function at the start of one of them (we can agree in which cases we would like to skip measuring sub-tests, e.g., in the case of unit tests, which are really fast).

References

Alternatives considered:

@@ -1,6 +1,6 @@
module github.com/Snowflake-Labs/terraform-provider-snowflake

go 1.22.10
go 1.24.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're upgrading to 1.23 in another PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know; this should be reversed to the one used in dev. I had to bump to see if t.Context() would be helpful.

@@ -10,8 +10,64 @@ import (
"github.com/stretchr/testify/require"
)

func TestATest(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving to pkg/internal/measurement/

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll either move or remove it completely. It was used only for testing purposes.


var testMeasurements = measurement.NewTestMeasurements()

func measureTest(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it belong to measurement package?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because you want to have separate lists for unit, integration, and acceptance tests. Separate method ensures the right default container is used (the body is in measurement package anyway, so most of the part is extracted).

}
}
}
t.Cleanup(func() { m.Duration = time.Now().Sub(start) })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add a method in TestMeasurement for this.

if value, ok := currentMeasurement.SubMeasurements[part]; ok {
currentMeasurement = value
} else {
m.TestName = strings.Join(testNameParts[index+1:], "/")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not clear, why we're omitting the previous parts and joining the next ones?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only for visualization purposes, instead of seeing

Test
-> Test/Sub-Test

you'll see

Test
-> Sub-Test

start := time.Now()
m := NewTestMeasurement(t)
testNameParts := strings.Split(m.TestName, "/")
if len(testNameParts) == 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: IMO this whole block could be extracted and simplified as a recursion. Also, why we're not doing a map check with panic in else?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be done with recursion, but this also works. I'll see next why I didn't check for panic (or value presence in the map).

return m
}

type TestMeasurements struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we really need this. Can we just pass []TestMeasurement to the functions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it could be like that, I'll take a look next time.

Copy link

Integration tests failure for 54be08ad23a2f9f1ca3549c88d4b5958ca0f7b69

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants