From 4c77d0e3b0dc14fe7b30baa0dcccfae5520b4639 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch Date: Mon, 23 Sep 2019 16:43:12 -0700 Subject: [PATCH 1/3] services/ticker: break the test consistently --- .../internal/tickerdb/queries_asset_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/services/ticker/internal/tickerdb/queries_asset_test.go b/services/ticker/internal/tickerdb/queries_asset_test.go index b1fcb6677a..c2e308ee52 100644 --- a/services/ticker/internal/tickerdb/queries_asset_test.go +++ b/services/ticker/internal/tickerdb/queries_asset_test.go @@ -1,8 +1,10 @@ package tickerdb import ( + "reflect" "testing" "time" + "unsafe" _ "github.com/lib/pq" migrate "github.com/rubenv/sql-migrate" @@ -50,7 +52,18 @@ func TestInsertOrUpdateAsset(t *testing.T) { require.NoError(t, err) // Creating first asset: - firstTime := time.Now() + //firstTime := time.Now() + firstTimeTmpl := &time.Time{} + { + firstTimeValue := reflect.ValueOf(firstTimeTmpl).Elem() + wallField := firstTimeValue.FieldByName("wall") + reflect.NewAt(wallField.Type(), unsafe.Pointer(wallField.UnsafeAddr())).Elem().SetUint(0xbf5a63f0b825c654) + extField := firstTimeValue.FieldByName("ext") + reflect.NewAt(extField.Type(), unsafe.Pointer(extField.UnsafeAddr())).Elem().SetInt(353520401) + locField := firstTimeValue.FieldByName("loc") + reflect.NewAt(locField.Type(), unsafe.Pointer(locField.UnsafeAddr())).Elem().Set(reflect.ValueOf(time.Local)) + } + firstTime := *firstTimeTmpl a := Asset{ Code: code, IssuerAccount: issuerAccount, From b96f35facaf6803fb55972ce8d119dd55a874371 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch Date: Mon, 23 Sep 2019 16:43:44 -0700 Subject: [PATCH 2/3] services/ticker: fix the test for 90% of cases with truncate => round --- .../internal/tickerdb/queries_asset_test.go | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/services/ticker/internal/tickerdb/queries_asset_test.go b/services/ticker/internal/tickerdb/queries_asset_test.go index c2e308ee52..dda448ce9c 100644 --- a/services/ticker/internal/tickerdb/queries_asset_test.go +++ b/services/ticker/internal/tickerdb/queries_asset_test.go @@ -88,13 +88,13 @@ func TestInsertOrUpdateAsset(t *testing.T) { assert.Equal(t, dbIssuer.ID, dbAsset1.IssuerID) assert.Equal( t, - firstTime.Local().Truncate(time.Millisecond), - dbAsset1.LastValid.Local().Truncate(time.Millisecond), + firstTime.Local().Round(time.Millisecond), + dbAsset1.LastValid.Local().Round(time.Millisecond), ) assert.Equal( t, - firstTime.Local().Truncate(time.Millisecond), - dbAsset1.LastChecked.Local().Truncate(time.Millisecond), + firstTime.Local().Round(time.Millisecond), + dbAsset1.LastChecked.Local().Round(time.Millisecond), ) // Creating Seconde Asset: @@ -122,13 +122,13 @@ func TestInsertOrUpdateAsset(t *testing.T) { assert.True(t, dbAsset2.LastChecked.After(firstTime)) assert.Equal( t, - secondTime.Local().Truncate(time.Millisecond), - dbAsset2.LastValid.Local().Truncate(time.Millisecond), + secondTime.Local().Round(time.Millisecond), + dbAsset2.LastValid.Local().Round(time.Millisecond), ) assert.Equal( t, - secondTime.Local().Truncate(time.Millisecond), - dbAsset2.LastChecked.Local().Truncate(time.Millisecond), + secondTime.Local().Round(time.Millisecond), + dbAsset2.LastChecked.Local().Round(time.Millisecond), ) // Creating Third Asset: @@ -155,12 +155,12 @@ func TestInsertOrUpdateAsset(t *testing.T) { assert.True(t, dbAsset3.LastChecked.Before(thirdTime)) assert.Equal( t, - dbAsset2.LastValid.Local().Truncate(time.Millisecond), - dbAsset3.LastValid.Local().Truncate(time.Millisecond), + dbAsset2.LastValid.Local().Round(time.Millisecond), + dbAsset3.LastValid.Local().Round(time.Millisecond), ) assert.Equal( - t, dbAsset2.LastValid.Local().Truncate(time.Millisecond), - dbAsset3.LastChecked.Local().Truncate(time.Millisecond), + t, dbAsset2.LastValid.Local().Round(time.Millisecond), + dbAsset3.LastChecked.Local().Round(time.Millisecond), ) } From 9bd40926b815790199df260210c79992ccabce81 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch Date: Mon, 23 Sep 2019 16:46:23 -0700 Subject: [PATCH 3/3] services/ticker: remove code added in first step to prove it out --- .../internal/tickerdb/queries_asset_test.go | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/services/ticker/internal/tickerdb/queries_asset_test.go b/services/ticker/internal/tickerdb/queries_asset_test.go index dda448ce9c..af810af6ed 100644 --- a/services/ticker/internal/tickerdb/queries_asset_test.go +++ b/services/ticker/internal/tickerdb/queries_asset_test.go @@ -1,10 +1,8 @@ package tickerdb import ( - "reflect" "testing" "time" - "unsafe" _ "github.com/lib/pq" migrate "github.com/rubenv/sql-migrate" @@ -52,18 +50,7 @@ func TestInsertOrUpdateAsset(t *testing.T) { require.NoError(t, err) // Creating first asset: - //firstTime := time.Now() - firstTimeTmpl := &time.Time{} - { - firstTimeValue := reflect.ValueOf(firstTimeTmpl).Elem() - wallField := firstTimeValue.FieldByName("wall") - reflect.NewAt(wallField.Type(), unsafe.Pointer(wallField.UnsafeAddr())).Elem().SetUint(0xbf5a63f0b825c654) - extField := firstTimeValue.FieldByName("ext") - reflect.NewAt(extField.Type(), unsafe.Pointer(extField.UnsafeAddr())).Elem().SetInt(353520401) - locField := firstTimeValue.FieldByName("loc") - reflect.NewAt(locField.Type(), unsafe.Pointer(locField.UnsafeAddr())).Elem().Set(reflect.ValueOf(time.Local)) - } - firstTime := *firstTimeTmpl + firstTime := time.Now() a := Asset{ Code: code, IssuerAccount: issuerAccount,