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

fix: test-race failure #159

Merged
merged 7 commits into from
May 3, 2021
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
144 changes: 71 additions & 73 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,80 +198,78 @@ jobs:
file: ./coverage.txt
if: env.GIT_DIFF

# TODO: disable test-race. please enable this after fixing concurrent checkTx
#
# test-race:
# runs-on: ubuntu-latest
# needs: split-test-files
# strategy:
# fail-fast: false
# matrix:
# part: ["00", "01", "02", "03"]
# steps:
# - name: Configure git for private modules
# env:
# TOKEN: ${{ secrets.TOKEN }}
# run: git config --global url."https://${TOKEN}:[email protected]".insteadOf "https://github.com"
# - uses: actions/checkout@v2
# - uses: actions/[email protected]
# with:
# go-version: 1.15
# - uses: technote-space/get-diff-action@v4
# with:
# PATTERNS: |
# **/**.go
# go.mod
# go.sum
# - uses: actions/download-artifact@v2
# with:
# name: "${{ github.sha }}-${{ matrix.part }}"
# if: env.GIT_DIFF
# - name: test & coverage report creation
# run: |
# xargs --arg-file=pkgs.txt.part.${{ matrix.part }} go test -mod=readonly -json -timeout 30m -race -tags='cgo ledger test_ledger_mock goleveldb' | tee ${{ matrix.part }}-race-output.txt
# if: env.GIT_DIFF
# - uses: actions/upload-artifact@v2
# with:
# name: "${{ github.sha }}-${{ matrix.part }}-race-output"
# path: ./${{ matrix.part }}-race-output.txt
test-race:
runs-on: ubuntu-latest
needs: split-test-files
strategy:
fail-fast: false
matrix:
part: ["00", "01", "02", "03"]
steps:
- name: Configure git for private modules
env:
TOKEN: ${{ secrets.TOKEN }}
run: git config --global url."https://${TOKEN}:[email protected]".insteadOf "https://github.com"
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
go-version: 1.15
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: actions/download-artifact@v2
with:
name: "${{ github.sha }}-${{ matrix.part }}"
if: env.GIT_DIFF
- name: test & coverage report creation
run: |
xargs --arg-file=pkgs.txt.part.${{ matrix.part }} go test -mod=readonly -json -timeout 30m -race -tags='cgo ledger test_ledger_mock goleveldb' | tee ${{ matrix.part }}-race-output.txt
if: env.GIT_DIFF
- uses: actions/upload-artifact@v2
with:
name: "${{ github.sha }}-${{ matrix.part }}-race-output"
path: ./${{ matrix.part }}-race-output.txt

# race-detector-report:
# runs-on: ubuntu-latest
# needs: [test-race, install-tparse]
# timeout-minutes: 5
# steps:
# - uses: actions/checkout@v2
# - uses: technote-space/get-diff-action@v4
# id: git_diff
# with:
# PATTERNS: |
# **/**.go
# go.mod
# go.sum
# - uses: actions/download-artifact@v2
# with:
# name: "${{ github.sha }}-00-race-output"
# if: env.GIT_DIFF
# - uses: actions/download-artifact@v2
# with:
# name: "${{ github.sha }}-01-race-output"
# if: env.GIT_DIFF
# - uses: actions/download-artifact@v2
# with:
# name: "${{ github.sha }}-02-race-output"
# if: env.GIT_DIFF
# - uses: actions/download-artifact@v2
# with:
# name: "${{ github.sha }}-03-race-output"
# if: env.GIT_DIFF
# - uses: actions/[email protected]
# with:
# path: ~/go/bin
# key: ${{ runner.os }}-go-tparse-binary
# if: env.GIT_DIFF
# - name: Generate test report (go test -race)
# run: cat ./*-race-output.txt | ~/go/bin/tparse
# if: env.GIT_DIFF
race-detector-report:
runs-on: ubuntu-latest
needs: [test-race, install-tparse]
timeout-minutes: 5
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v4
id: git_diff
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: actions/download-artifact@v2
with:
name: "${{ github.sha }}-00-race-output"
if: env.GIT_DIFF
- uses: actions/download-artifact@v2
with:
name: "${{ github.sha }}-01-race-output"
if: env.GIT_DIFF
- uses: actions/download-artifact@v2
with:
name: "${{ github.sha }}-02-race-output"
if: env.GIT_DIFF
- uses: actions/download-artifact@v2
with:
name: "${{ github.sha }}-03-race-output"
if: env.GIT_DIFF
- uses: actions/[email protected]
with:
path: ~/go/bin
key: ${{ runner.os }}-go-tparse-binary
if: env.GIT_DIFF
- name: Generate test report (go test -race)
run: cat ./*-race-output.txt | ~/go/bin/tparse
if: env.GIT_DIFF

# TODO ebony: enable this test
# liveness-test:
Expand Down
12 changes: 9 additions & 3 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
panic(err)
}

// set the signed validators for addition to context in deliverTx
app.voteInfos = req.LastCommitInfo.GetVotes()

// Initialize the DeliverTx state. If this is the first block, it should
// already be initialized in InitChain. Otherwise app.deliverState will be
// nil, since it is reset on Commit.
Expand All @@ -173,14 +176,15 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
gasMeter = sdk.NewInfiniteGasMeter()
}

app.deliverState.ctx = app.deliverState.ctx.WithBlockGasMeter(gasMeter)
app.deliverState.ctx = app.deliverState.ctx.WithBlockGasMeter(gasMeter).
WithVoteInfos(app.voteInfos).
WithConsensusParams(app.GetConsensusParams(app.deliverState.ctx))
wetcod marked this conversation as resolved.
Show resolved Hide resolved

if app.beginBlocker != nil {
res = app.beginBlocker(app.deliverState.ctx, req)
res.Events = sdk.MarkEventsToIndex(res.Events, app.indexEvents)
}
// set the signed validators for addition to context in deliverTx
app.voteInfos = req.LastCommitInfo.GetVotes()

return res
}

Expand Down Expand Up @@ -654,9 +658,11 @@ func (app *BaseApp) createQueryContext(height int64, prove bool) (sdk.Context, e
}

// branch the commit-multistore for safety
app.checkStateMtx.RLock()
ctx := sdk.NewContext(
cacheMS, app.checkState.ctx.BlockHeader(), true, app.logger,
).WithMinGasPrices(app.minGasPrices)
app.checkStateMtx.RUnlock()

return ctx, nil
}
Expand Down
10 changes: 4 additions & 6 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ func (app *BaseApp) setCheckState(header ostproto.Header) {
defer app.checkStateMtx.Unlock()

ctx := sdk.NewContext(ms, header, true, app.logger).
WithMinGasPrices(app.minGasPrices)
WithMinGasPrices(app.minGasPrices).
WithVoteInfos(app.voteInfos)

app.checkState = &state{
ms: ms,
Expand Down Expand Up @@ -528,11 +529,8 @@ func (app *BaseApp) getRunContextForTx(txBytes []byte, simulate bool) sdk.Contex
}

func (app *BaseApp) getContextForTx(s *state, txBytes []byte) sdk.Context {
ctx := s.ctx.
WithTxBytes(txBytes).
WithVoteInfos(app.voteInfos)

return ctx.WithConsensusParams(app.GetConsensusParams(ctx))
ctx := s.ctx.WithTxBytes(txBytes)
return ctx
}

// cacheTxContext returns a new context based off of the provided context with
Expand Down
35 changes: 35 additions & 0 deletions client/keys/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package keys

import (
"bytes"
"testing"

"github.com/line/lbm-sdk/v2/client"
"github.com/line/lbm-sdk/v2/crypto/hd"
"github.com/line/lbm-sdk/v2/crypto/keyring"
"github.com/line/lbm-sdk/v2/testutil"
"github.com/line/lbm-sdk/v2/types"
"github.com/stretchr/testify/require"
)

func Test_printInfos(t *testing.T) {
cmd := ListKeysCmd()
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())

kbHome := t.TempDir()

mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
kb, err := keyring.New(types.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn)
require.NoError(t, err)

kb.NewAccount("something", testutil.TestMnemonic, "", "", hd.Secp256k1)

clientCtx := client.Context{}.WithKeyring(kb)
require.NoError(t, err)

infos, err := clientCtx.Keyring.List()
require.NoError(t, err)
buf := bytes.NewBufferString("")
printInfos(buf, infos, OutputFormatJSON)
require.Equal(t, buf.String(), "[{\"name\":\"something\",\"type\":\"local\",\"address\":\"link1jyyxx9phqw6tarnxanhyx7ecr992d6yrztj4d0\",\"pubkey\":\"linkpub1cqmsrdepqg8qdahungt0uladr5g4v6kh56x4wx7auws5rfxunyrapnqn7kfkyrszyvh\"}]")
}
17 changes: 17 additions & 0 deletions simapp/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"testing"

"github.com/line/ostracon/abci/types"
types2 "github.com/line/ostracon/proto/ostracon/types"
"github.com/stretchr/testify/require"

"github.com/line/lbm-sdk/v2/codec"
Expand All @@ -23,6 +25,21 @@ func makeCodec(bm module.BasicManager) *codec.LegacyAmino {
return cdc
}

func TestSetup(t *testing.T) {
app := Setup(false)
ctx := app.BaseApp.NewContext(false, types2.Header{})

app.InitChain(
types.RequestInitChain{
AppStateBytes: []byte("{}"),
ChainId: "test-chain-id",
},
)

acc := app.AccountKeeper.GetAccount(ctx, authtypes.NewModuleAddress(authtypes.FeeCollectorName))
require.NotNil(t, acc)
}

func TestGetSimulationLog(t *testing.T) {
cdc := makeCodec(ModuleBasics)

Expand Down