edgedb-go
edgedb-go copied to clipboard
Document go time nanosecond precision on linux x86_64
This caused a bit of confusion when tests started failing when moving unit tests into a linux container from my mac workstation. Not the fault of edgedb-go but may be a good edge case to document for others.
It appears time.Now()
on certain platforms can generate more than 6 decimal places of nanosecond precision. ie: 2022-04-18 22:13:26.9245872 +0000 UTC
on linux x86_64 as one example
However edgedb only stores up to 6 digits of nanosecond precision (postgres thing?)
edgedb> select <datetime>'2022-04-18T17:54:23.1876103-04:00';
{<datetime>'2022-04-18T21:54:23.187610Z'}
An example test that always passes on my intel mac workstation, but will intermittently fail inside a linux container:
func Test_time_precision(t *testing.T) {
now := time.Now().UTC()
t.Logf("now: %s", now)
var result time.Time
query := "select <datetime>$now"
args := map[string]any{"now": now}
err := TestClient.QuerySingle(TestContext, query, &result, args)
assert.NoError(t, err)
t.Logf("result: %s", result)
t.Logf("same: %v", now.Equal(result))
}
Consistent pass on mac:
=== RUN Test_time_precision
test.go:168: now: 2022-04-18 22:21:02.126656 +0000 UTC
test.go:174: result: 2022-04-18 22:21:02.126656 +0000 UTC
est.go:175: same: true
Intermittent failure in linux container:
=== RUN Test_time_precision
test.go:168: now: 2022-04-18 22:13:26.9245872 +0000 UTC
test.go:174: result: 2022-04-18 22:13:26.924587 +0000 UTC
test.go:175: same: false
one naive option is to round both values before comparing:
assert.Equal(t, now.Round(1000*time.Nanosecond), result.Round(1000*time.Nanosecond))
Thanks for pointing this out! I wonder if this should go in the docs for the datetime
type and other cal::*
types in the edgedb/edgedb repo :thinking:
cc @1st1 @colinhacks