Skip to content

Conversation

@thaJeztah
Copy link
Member

pkg/epoch: replace some fmt.Sprintfs with strconv

Teeny-tiny optimizations:

BenchmarkSprintf-10       37735996    32.31  ns/op  0 B/op  0 allocs/op
BenchmarkItoa-10         591945836     2.031 ns/op  0 B/op  0 allocs/op
BenchmarkFormatUint-10   593701444     2.014 ns/op  0 B/op  0 allocs/op

pkg/epoch: fix tests on macOS

These tests were failing on my macOS; could be the precision issue (like on
Windows), or just because they're "too fast".

=== RUN   TestSourceDateEpoch/WithoutSourceDateEpoch
    epoch_test.go:51: 
            Error Trace:	/Users/thajeztah/go/src/github.com/containerd/containerd/pkg/epoch/epoch_test.go:51
            Error:      	Should be true
            Test:       	TestSourceDateEpoch/WithoutSourceDateEpoch
            Messages:   	now: 2023-06-23 11:47:09.93118 +0000 UTC, v: 2023-06-23 11:47:09.93118 +0000 UTC

This patch:

  • updates the rightAfter utility to allow the timestamps to be "equal"
  • updates the asserts to provide some details about the timestamps
  • uses UTC for the value we're comparing to, to match the timestamps
    that are generated.

pkg/epoch: extract parsing SOURCE_DATE_EPOCH to a function

This introduces a ParseSourceDateEpoch function, which can be used
to parse "SOURCE_DATE_EPOCH" values for situations where those
values are not passed through an env-var (or the env-var has been
read through other means).

Teeny-tiny optimizations:

    BenchmarkSprintf-10       37735996    32.31  ns/op  0 B/op  0 allocs/op
    BenchmarkItoa-10         591945836     2.031 ns/op  0 B/op  0 allocs/op
    BenchmarkFormatUint-10   593701444     2.014 ns/op  0 B/op  0 allocs/op

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah requested a review from AkihiroSuda June 23, 2023 15:16
@thaJeztah
Copy link
Member Author

/cc @crazy-max

@k8s-ci-robot
Copy link

@thaJeztah: GitHub didn't allow me to request PR reviews from the following users: crazy-max.

Note that only containerd members and repo collaborators can review this PR, and authors cannot review their own PRs.

Details

In response to this:

/cc @crazy-max

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@thaJeztah thaJeztah force-pushed the epoch_export_parse branch from 68f3eeb to 0f7efca Compare June 23, 2023 15:18
@thaJeztah thaJeztah force-pushed the epoch_export_parse branch from 0f7efca to 4acae19 Compare June 23, 2023 15:26
These tests were failing on my macOS; could be the precision issue (like on
Windows), or just because they're "too fast".

    === RUN   TestSourceDateEpoch/WithoutSourceDateEpoch
        epoch_test.go:51:
                Error Trace:	/Users/thajeztah/go/src/github.com/containerd/containerd/pkg/epoch/epoch_test.go:51
                Error:      	Should be true
                Test:       	TestSourceDateEpoch/WithoutSourceDateEpoch
                Messages:   	now: 2023-06-23 11:47:09.93118 +0000 UTC, v: 2023-06-23 11:47:09.93118 +0000 UTC

This patch:

- updates the rightAfter utility to allow the timestamps to be "equal"
- updates the asserts to provide some details about the timestamps
- uses UTC for the value we're comparing to, to match the timestamps
  that are generated.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah force-pushed the epoch_export_parse branch from 4acae19 to 2b25a5f Compare June 23, 2023 15:30
This introduces a ParseSourceDateEpoch function, which can be used
to parse "SOURCE_DATE_EPOCH" values for situations where those
values are not passed through an env-var (or the env-var has been
read through other means).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah force-pushed the epoch_export_parse branch from 2b25a5f to 8760b87 Compare June 23, 2023 15:32
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.

5 participants