From 739ddf8e14d87f478d12ec6c64d1a76fab3f5e4b Mon Sep 17 00:00:00 2001 From: Steve Perkins Date: Mon, 22 Jan 2024 10:19:40 -0500 Subject: [PATCH] qm sync: handle non-200 status, more tests. (#7265) --- mediorum/server/qm_sync.go | 5 +++++ mediorum/server/qm_sync_test.go | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/mediorum/server/qm_sync.go b/mediorum/server/qm_sync.go index 516065305ba..68157610770 100644 --- a/mediorum/server/qm_sync.go +++ b/mediorum/server/qm_sync.go @@ -3,6 +3,7 @@ package server import ( "bufio" "context" + "fmt" "net/http" "time" @@ -71,6 +72,10 @@ func (ss *MediorumServer) pullQmFromPeer(host string) error { } defer req.Body.Close() + if req.StatusCode != 200 { + return fmt.Errorf("bad status %d", req.StatusCode) + } + tx, err := ss.pgPool.Begin(context.Background()) if err != nil { return err diff --git a/mediorum/server/qm_sync_test.go b/mediorum/server/qm_sync_test.go index 670ec95c730..5938f91f54a 100644 --- a/mediorum/server/qm_sync_test.go +++ b/mediorum/server/qm_sync_test.go @@ -48,4 +48,17 @@ func TestQmSync(t *testing.T) { s2.pgPool.QueryRow(ctx, "select count(*) = 1 from qm_sync where host = $1", ss.Config.Self.Host).Scan(&s2done) assert.True(t, s2done) + + var qm string + s2.pgPool.QueryRow(ctx, "select * from qm_cids order by key").Scan(&qm) + assert.Equal(t, "Qm1", qm) + + // run it again + err = s2.pullQmFromPeer(ss.Config.Self.Host) + assert.NoError(t, err) + + // force duplicate run + s2.pgPool.Exec(ctx, "truncate qm_sync") + err = s2.pullQmFromPeer(ss.Config.Self.Host) + assert.NoError(t, err) }