@@ -3,17 +3,18 @@ package algodimporter
33import (
44 "context"
55 "fmt"
6- "github.com/sirupsen/logrus"
7- "github.com/sirupsen/logrus/hooks/test"
8- "github.com/stretchr/testify/assert"
9- "github.com/stretchr/testify/require"
10- "gopkg.in/yaml.v3"
116 "net/http"
127 "net/http/httptest"
138 "strings"
149 "testing"
1510 "time"
1611
12+ "github.com/sirupsen/logrus"
13+ "github.com/sirupsen/logrus/hooks/test"
14+ "github.com/stretchr/testify/assert"
15+ "github.com/stretchr/testify/require"
16+ "gopkg.in/yaml.v3"
17+
1718 "github.com/algorand/go-algorand-sdk/v2/client/v2/algod"
1819 "github.com/algorand/go-algorand-sdk/v2/client/v2/common/models"
1920 sdk "github.com/algorand/go-algorand-sdk/v2/types"
@@ -681,34 +682,39 @@ func TestGetBlockErrors(t *testing.T) {
681682 name : "Cannot wait for block" ,
682683 rnd : 123 ,
683684 blockAfterResponder : MakeJsonResponderSeries ("/wait-for-block-after" , []int {http .StatusOK , http .StatusNotFound }, []interface {}{models.NodeStatus {LastRound : 1 }}),
684- err : fmt .Sprintf ("error getting block for round 123" ),
685+ blockResponder : nil ,
686+ deltaResponder : nil ,
687+ err : "error getting block for round 123" ,
685688 logs : []string {"error getting block for round 123" },
686689 },
687690 {
688691 name : "Cannot get block" ,
689692 rnd : 123 ,
690693 blockAfterResponder : BlockAfterResponder ,
691- deltaResponder : MakeMsgpStatusResponder ("get" , "/v2/deltas/" , http .StatusNotFound , sdk.LedgerStateDelta {}),
692694 blockResponder : MakeMsgpStatusResponder ("get" , "/v2/blocks/" , http .StatusNotFound , "" ),
693- err : fmt .Sprintf ("error getting block for round 123" ),
695+ deltaResponder : MakeMsgpStatusResponder ("get" , "/v2/deltas/" , http .StatusNotFound , sdk.LedgerStateDelta {}),
696+ err : "error getting block for round 123" ,
694697 logs : []string {"error getting block for round 123" },
695698 },
696699 {
697- name : "Cannot get delta ( node behind, re-send sync) " ,
700+ name : "Cannot get delta - node behind, re-send sync" ,
698701 rnd : 200 ,
699702 blockAfterResponder : MakeBlockAfterResponder (models.NodeStatus {LastRound : 50 }),
700703 blockResponder : BlockResponder ,
701704 deltaResponder : MakeMsgpStatusResponder ("get" , "/v2/deltas/" , http .StatusNotFound , "" ),
702- err : fmt .Sprintf ("wrong round returned from status for round: 50 != 200" ),
703- logs : []string {"wrong round returned from status for round: 50 != 200" , "Sync error detected, attempting to set the sync round to recover the node" },
705+ err : "wrong round returned from status for round: retrieved(50) != expected(200)" ,
706+ logs : []string {
707+ "wrong round returned from status for round: retrieved(50) != expected(200)" ,
708+ "sync error detected, attempting to set the sync round to recover the node" ,
709+ },
704710 },
705711 {
706- name : "Cannot get delta ( caught up) " ,
712+ name : "Cannot get delta - caught up" ,
707713 rnd : 200 ,
708714 blockAfterResponder : MakeBlockAfterResponder (models.NodeStatus {LastRound : 200 }),
709715 blockResponder : BlockResponder ,
710716 deltaResponder : MakeMsgpStatusResponder ("get" , "/v2/deltas/" , http .StatusNotFound , "" ),
711- err : fmt . Sprintf ( "ledger state delta not found: node round (200), required round (200)" ) ,
717+ err : "ledger state delta not found: node round (200), required round (200)" ,
712718 logs : []string {"ledger state delta not found: node round (200), required round (200)" },
713719 },
714720 }
@@ -752,21 +758,26 @@ func TestGetBlockErrors(t *testing.T) {
752758 _ , err = testImporter .GetBlock (tc .rnd )
753759 noError := assert .ErrorContains (t , err , tc .err )
754760
755- // Make sure each of the expected log messages are present
761+ // Make sure each of the expected log messages are present in the hookEntries
762+ hookEntries := hook .AllEntries ()
756763 for _ , log := range tc .logs {
757764 found := false
758- for _ , entry := range hook .AllEntries () {
759- fmt .Println (strings .Contains (entry .Message , log ))
760- found = found || strings .Contains (entry .Message , log )
765+ for _ , entry := range hookEntries {
766+ logIsSubstring := strings .Contains (entry .Message , log )
767+ found = found || logIsSubstring
768+ fmt .Printf ("logIsSubstring=%t, found=%t:\n \t %s\n " , logIsSubstring , found , entry .Message )
761769 }
762- noError = noError && assert .True (t , found , "Expected log was not found: '%s'" , log )
770+ if ! found {
771+ fmt .Printf (">>>>>>WE HAVE A PROBLEM<<<<<<\n " )
772+ }
773+ noError = noError && assert .True (t , found , "(%s) Expected log was not found: '%s'" , tc .name , log )
763774 }
764775
765776 // Print logs if there was an error.
766777 if ! noError {
767- fmt .Println ("An error was detected, printing logs" )
778+ fmt .Printf ("An error was detected, printing logs (%s) \n " , tc . name )
768779 fmt .Println ("------------------------------------" )
769- for _ , entry := range hook . AllEntries () {
780+ for _ , entry := range hookEntries {
770781 fmt .Printf (" %s\n " , entry .Message )
771782 }
772783 fmt .Println ("------------------------------------" )
0 commit comments