From a376608e8cd17016971ec1022f8891debf140388 Mon Sep 17 00:00:00 2001 From: PJ Date: Mon, 19 Feb 2024 15:37:48 +0100 Subject: [PATCH] stores: handle MySQL --- stores/hostdb_test.go | 7 +++++-- stores/metadata_test.go | 1 + stores/sql_test.go | 34 +++++++++++++++++++++++++--------- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/stores/hostdb_test.go b/stores/hostdb_test.go index a61f9eea3f..eb1e4a44f3 100644 --- a/stores/hostdb_test.go +++ b/stores/hostdb_test.go @@ -1100,8 +1100,11 @@ func (s *SQLStore) addTestHost(hk types.PublicKey) error { func (s *SQLStore) addCustomTestHost(hk types.PublicKey, na string) error { s.unappliedHostKeys[hk] = struct{}{} s.unappliedAnnouncements = append(s.unappliedAnnouncements, []announcement{{ - hostKey: publicKey(hk), - announcement: hostdb.Announcement{NetAddress: na}, + hostKey: publicKey(hk), + announcement: hostdb.Announcement{ + NetAddress: na, + Timestamp: time.Now(), + }, }}...) s.lastSave = time.Now().Add(s.persistInterval * -2) return s.applyUpdates(false) diff --git a/stores/metadata_test.go b/stores/metadata_test.go index 4a61023994..63c8dca2b3 100644 --- a/stores/metadata_test.go +++ b/stores/metadata_test.go @@ -1169,6 +1169,7 @@ func TestSQLMetadataStore(t *testing.T) { slabs[i].Shards[0].Model = Model{} slabs[i].Shards[0].Contracts[0].Model = Model{} slabs[i].Shards[0].Contracts[0].Host.Model = Model{} + slabs[i].Shards[0].Contracts[0].Host.LastAnnouncement = time.Time{} slabs[i].HealthValidUntil = 0 } if !reflect.DeepEqual(slab1, expectedObjSlab1) { diff --git a/stores/sql_test.go b/stores/sql_test.go index b0bbe695a0..9b7ed8022f 100644 --- a/stores/sql_test.go +++ b/stores/sql_test.go @@ -314,13 +314,17 @@ func TestConsensusReset(t *testing.T) { } } -type queryPlanExplain struct { +type sqliteQueryPlan struct { ID int `json:"id"` Parent int `json:"parent"` NotUsed bool `json:"notused"` Detail string `json:"detail"` } +type mysqlQueryPlan struct { + Extra string `json:"extra"` +} + func TestQueryPlan(t *testing.T) { ss := newTestSQLStore(t, defaultTestSQLStoreConfig) defer ss.Close() @@ -354,14 +358,26 @@ func TestQueryPlan(t *testing.T) { } for _, query := range queries { - var explain queryPlanExplain - err := ss.db.Raw(fmt.Sprintf("EXPLAIN QUERY PLAN %s;", query)).Scan(&explain).Error - if err != nil { - t.Fatal(err) - } - if !(strings.Contains(explain.Detail, "USING INDEX") || - strings.Contains(explain.Detail, "USING COVERING INDEX")) { - t.Fatalf("query '%s' should use an index, instead the plan was '%s'", query, explain.Detail) + if isSQLite(ss.db) { + var explain sqliteQueryPlan + err := ss.db.Raw(fmt.Sprintf("EXPLAIN QUERY PLAN %s;", query)).Scan(&explain).Error + if err != nil { + t.Fatal(err) + } + if !(strings.Contains(explain.Detail, "USING INDEX") || + strings.Contains(explain.Detail, "USING COVERING INDEX")) { + t.Fatalf("query '%s' should use an index, instead the plan was '%s'", query, explain.Detail) + } + } else { + var explain mysqlQueryPlan + err := ss.db.Raw(fmt.Sprintf("EXPLAIN QUERY PLAN %s;", query)).Scan(&explain).Error + if err != nil { + t.Fatal(err) + } + if !(strings.Contains(strings.ToLower(explain.Extra), "using index")) { + t.Fatalf("query '%s' should use an index, instead the plan was '%s'", query, explain.Extra) + } + } } }