Skip to content

Commit

Permalink
qm sync: handle non-200 status, more tests. (#7265)
Browse files Browse the repository at this point in the history
  • Loading branch information
stereosteve authored Jan 22, 2024
1 parent 64e38bc commit 739ddf8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mediorum/server/qm_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"bufio"
"context"
"fmt"
"net/http"
"time"

Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions mediorum/server/qm_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 739ddf8

Please sign in to comment.