Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qm sync: handle non-200 status, more tests. #7265

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}