Skip to content

Commit

Permalink
fix: test race + gomodtidy
Browse files Browse the repository at this point in the history
  • Loading branch information
aalu1418 committed May 20, 2024
1 parent 66a4a00 commit bcfca66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.21.7
replace github.com/smartcontractkit/chainlink-solana => ../

require (
github.com/ethereum/go-ethereum v1.13.8
github.com/gagliardetto/binary v0.7.7
github.com/gagliardetto/solana-go v1.8.4
github.com/google/uuid v1.6.0
Expand Down Expand Up @@ -136,6 +135,7 @@ require (
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
github.com/esote/minmaxheap v1.0.0 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/ethereum/go-ethereum v1.13.8 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
Expand Down
11 changes: 11 additions & 0 deletions pkg/solana/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"math/big"
"net/http"
"net/http/httptest"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -150,7 +151,13 @@ func TestGetLatestTransmission(t *testing.T) {

func TestCache(t *testing.T) {
ctx := tests.Context(t)

var lock sync.RWMutex // prevent race between cache + server shutdown
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// use RLock to allow parallel server calls
lock.RLock()
defer lock.RUnlock()

// create response
body, err := io.ReadAll(r.Body)
require.NoError(t, err)
Expand Down Expand Up @@ -196,7 +203,11 @@ func TestCache(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, expectedTime, answer.Timestamp)
assert.Equal(t, expectedAns, answer.Data.String())

// use write lock to shutdown server to prevent read/write race
lock.Lock()
mockServer.Close()
lock.Unlock()
}

func TestNilPointerHandling(t *testing.T) {
Expand Down

0 comments on commit bcfca66

Please sign in to comment.