Commit 37bac459 authored by kingwang's avatar kingwang Committed by vipwzw

fix para test

parent 7667a9dc
package testnode package testnode
var paraconfig = ` //default config for testnode
var DefaultConfig = `
Title="user.p.guodun." Title="user.p.guodun."
# TestNet=true # TestNet=true
...@@ -71,6 +72,9 @@ poolCacheSize=10240 ...@@ -71,6 +72,9 @@ poolCacheSize=10240
minTxFee=100000 minTxFee=100000
maxTxNumPerAccount=10000 maxTxNumPerAccount=10000
[mempool.sub.para]
poolCacheSize=102400
[consensus] [consensus]
name="para" name="para"
genesisBlockTime=1514533394 genesisBlockTime=1514533394
......
...@@ -23,7 +23,7 @@ func NewParaNode(main *testnode.Chain33Mock, para *testnode.Chain33Mock) *ParaNo ...@@ -23,7 +23,7 @@ func NewParaNode(main *testnode.Chain33Mock, para *testnode.Chain33Mock) *ParaNo
main.Listen() main.Listen()
} }
if para == nil { if para == nil {
cfg, sub := types.InitCfgString(paraconfig) cfg, sub := types.InitCfgString(DefaultConfig)
testnode.ModifyParaClient(sub, main.GetCfg().RPC.GrpcBindAddr) testnode.ModifyParaClient(sub, main.GetCfg().RPC.GrpcBindAddr)
para = testnode.NewWithConfig(cfg, sub, nil) para = testnode.NewWithConfig(cfg, sub, nil)
para.Listen() para.Listen()
......
...@@ -46,7 +46,6 @@ func NewMempool(cfg *types.Mempool) *Mempool { ...@@ -46,7 +46,6 @@ func NewMempool(cfg *types.Mempool) *Mempool {
func (mem *Mempool) SetQueueClient(client queue.Client) { func (mem *Mempool) SetQueueClient(client queue.Client) {
mem.client = client mem.client = client
mem.client.Sub(mem.key) mem.client.Sub(mem.key)
mem.wg.Add(1) mem.wg.Add(1)
go func() { go func() {
for msg := range client.Recv() { for msg := range client.Recv() {
...@@ -69,8 +68,7 @@ func (mem *Mempool) SetQueueClient(client queue.Client) { ...@@ -69,8 +68,7 @@ func (mem *Mempool) SetQueueClient(client queue.Client) {
} }
} }
default: default:
msg.Reply(client.NewMessage(mem.key, types.EventReply, &types.Reply{IsOk: false, msg.Reply(client.NewMessage(mem.key, types.EventReply, types.ErrActionNotSupport))
Msg: []byte(fmt.Sprintf("para %v doesn't handle message %v", mem.key, msg.Ty))}))
} }
} }
}() }()
...@@ -81,10 +79,9 @@ func (mem *Mempool) Wait() {} ...@@ -81,10 +79,9 @@ func (mem *Mempool) Wait() {}
// Close method // Close method
func (mem *Mempool) Close() { func (mem *Mempool) Close() {
if mem.isClose() { if !atomic.CompareAndSwapInt32(&mem.isclose, 0, 1) {
return return
} }
atomic.StoreInt32(&mem.isclose, 1)
if mem.client != nil { if mem.client != nil {
mem.client.Close() mem.client.Close()
} }
...@@ -93,7 +90,3 @@ func (mem *Mempool) Close() { ...@@ -93,7 +90,3 @@ func (mem *Mempool) Close() {
mem.wg.Wait() mem.wg.Wait()
mlog.Info("para mempool module closed") mlog.Info("para mempool module closed")
} }
func (mem *Mempool) isClose() bool {
return atomic.LoadInt32(&mem.isclose) == 1
}
package para_test
import (
"testing"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
"github.com/33cn/chain33/util/testnode"
paratest "github.com/33cn/plugin/plugin/dapp/paracross/testnode"
"github.com/33cn/plugin/plugin/mempool/para"
"github.com/stretchr/testify/assert"
_ "github.com/33cn/chain33/system"
_ "github.com/33cn/plugin/plugin"
)
func TestClose(t *testing.T) {
mem := para.NewMempool(nil)
n := 1000
done := make(chan struct{}, n)
for i := 0; i < n; i++ {
go func() {
mem.Close()
done <- struct{}{}
}()
}
for i := 0; i < n; i++ {
<-done
}
}
func TestParaNodeMempool(t *testing.T) {
main := testnode.New("", nil)
main.Listen()
cfg, sub := types.InitCfgString(paratest.DefaultConfig)
testnode.ModifyParaClient(sub, main.GetCfg().RPC.GrpcBindAddr)
cfg.Mempool.Name = "para"
para := testnode.NewWithConfig(cfg, sub, nil)
para.Listen()
mockpara := paratest.NewParaNode(main, para)
tx := util.CreateTxWithExecer(mockpara.Para.GetGenesisKey(), "user.p.guodun.none")
hash := mockpara.Para.SendTx(tx)
assert.Equal(t, tx.Hash(), hash)
_, err := mockpara.Para.GetAPI().GetMempool()
assert.Equal(t, err, types.ErrActionNotSupport)
t.Log(err)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment