forked from algorand/indexer
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutil_test.go
More file actions
59 lines (47 loc) · 1.37 KB
/
util_test.go
File metadata and controls
59 lines (47 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package api
import (
"context"
"errors"
"testing"
"time"
"github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/require"
"github.com/algorand/go-algorand-sdk/v2/types"
"github.com/algorand/indexer/v3/idb"
)
func TestCallWithTimeoutTimesOut(t *testing.T) {
done := make(chan struct{})
defer func() {
close(done)
}()
logger, hook := test.NewNullLogger()
err := callWithTimeout(context.Background(), logger, 1*time.Nanosecond, func(ctx context.Context) error {
<-done
return errors.New("should not return")
})
require.Error(t, err)
require.ErrorIs(t, err, errTimeout)
time.Sleep(2 * time.Second)
require.Len(t, hook.Entries, 1)
require.Equal(t, errMisbehavingHandler, hook.LastEntry().Message)
}
func TestCallWithTimeoutExitsWhenHandlerFinishes(t *testing.T) {
done := make(chan struct{})
defer func() {
<-done
}()
callError := errors.New("this should be the result")
err := callWithTimeout(context.Background(), nil, 1*time.Minute, func(ctx context.Context) error {
defer close(done)
return callError
})
require.Error(t, err)
require.ErrorIs(t, err, callError)
}
func TestInvalidTxnRow(t *testing.T) {
stxn := types.SignedTxnWithAD{}
invalidRow := idb.TxnRow{Txn: &stxn, RootTxn: &stxn}
_, err := txnRowToTransaction(invalidRow)
require.Error(t, err)
require.ErrorContains(t, err, "Txn and RootTxn should be mutually exclusive")
}