Fix issue with uncommited transaction

This commit is contained in:
Netscape Navigator 2020-09-27 08:46:44 -05:00
parent 24a30d0121
commit 7aadc1ad4a
2 changed files with 8 additions and 3 deletions

View File

@ -39,6 +39,11 @@ func addPeer(mHash string, status PeerStatus) {
}
_, err2 := tx.Exec(createPeer, mHash, status)
if err2 != nil {
// This .Commit() call never gets hit:
err1 := tx.Rollback()
if err1 != nil {
panicf("Failed to rollback peer (1): %s", err)
}
panic(fmt.Sprintf("Failure. Possible duplicate peer?: %s", err2))
}
err1 := tx.Commit()

View File

@ -26,9 +26,9 @@ func TestGetPeerStatus(t *testing.T) {
func TestAddPeer(t *testing.T) {
defer func() {
r := recover()
if r != nil {
err := "Should not be able to block and follow at the same time"
t.Errorf(err)
if r == nil {
err := "Should not be able to block and follow at the same time %s"
t.Errorf(err, r)
}
}()
resetDB()