Skip to content

BlobInfoCache’s assumption that time.Now() values are unique is incorrect #1035

Description

@mtrmac

time.Now() returns nanosecond values but that doesn’t mean that the resolution of the returned values is a single nanosecond.

E.g. macOS seems to only return microsecond values, and a simple loop like

	last := time.Now()
	for i := 0; i < attempts; i += 1 {
		t := time.Now()
		if t == last {
			fmt.Printf("%d\n", i)
			count++
		}
		last = t
	}

shows 4 % of duplicates.

This does not really matter for “correctness” of BlobInfoCache, but tests assume that the values are unique and guarantee deterministic ordering, e.g. in #1030 , FAIL: TestNew/with_Open:_RecordKnownLocations with

        	            	expected: []types.BICReplacementCandidate{types.BICReplacementCandidate{Digest:"sha256:3333333333333333333333333333333333333333333333333333333333333333", Location:types.BICLocationReference{Opaque:"A1"}}, types.BICReplacementCandidate{Digest:"sha256:3333333333333333333333333333333333333333333333333333333333333333", Location:types.BICLocationReference{Opaque:"A2"}}}
        	            	actual  : []types.BICReplacementCandidate{types.BICReplacementCandidate{Digest:"sha256:3333333333333333333333333333333333333333333333333333333333333333", Location:types.BICLocationReference{Opaque:"A2"}}, types.BICReplacementCandidate{Digest:"sha256:3333333333333333333333333333333333333333333333333333333333333333", Location:types.BICLocationReference{Opaque:"A1"}}}

Fix at least that one (by sleeping in the test?), and perhaps look for other instances of such an assumption in the BIC tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions