How to use Wait method of proxyapp Package

Best Syzkaller code snippet using proxyapp.Wait

replay_test.go

Source:replay_test.go Github

copy

Full Screen

...41// WAL Tests42// TODO: It would be better to verify explicitly which states we can recover from without the wal43// and which ones we need the wal for - then we'd also be able to only flush the44// wal writer when we need to, instead of with every message.45func startNewConsensusStateAndWaitForBlock(t *testing.T, lastBlockHeight int64, blockDB dbm.DB, stateDB dbm.DB) {46 logger := log.TestingLogger()47 state, _ := sm.LoadStateFromDBOrGenesisFile(stateDB, consensusReplayConfig.GenesisFile())48 privValidator := loadPrivValidator(consensusReplayConfig)49 cs := newConsensusStateWithConfigAndBlockStore(consensusReplayConfig, state, privValidator, kvstore.NewKVStoreApplication(), blockDB)50 cs.SetLogger(logger)51 bytes, _ := ioutil.ReadFile(cs.config.WalFile())52 // fmt.Printf("====== WAL: \n\r%s\n", bytes)53 t.Logf("====== WAL: \n\r%X\n", bytes)54 err := cs.Start()55 require.NoError(t, err)56 defer cs.Stop()57 // This is just a signal that we haven't halted; its not something contained58 // in the WAL itself. Assuming the consensus state is running, replay of any59 // WAL, including the empty one, should eventually be followed by a new60 // block, or else something is wrong.61 newBlockCh := make(chan interface{}, 1)62 err = cs.eventBus.Subscribe(context.Background(), testSubscriber, types.EventQueryNewBlock, newBlockCh)63 require.NoError(t, err)64 select {65 case <-newBlockCh:66 case <-time.After(60 * time.Second):67 t.Fatalf("Timed out waiting for new block (see trace above)")68 }69}70func sendTxs(cs *ConsensusState, ctx context.Context) {71 for i := 0; i < 256; i++ {72 select {73 case <-ctx.Done():74 return75 default:76 tx := []byte{byte(i)}77 cs.mempool.CheckTx(tx, nil)78 i++79 }80 }81}82// TestWALCrash uses crashing WAL to test we can recover from any WAL failure.83func TestWALCrash(t *testing.T) {84 testCases := []struct {85 name string86 initFn func(dbm.DB, *ConsensusState, context.Context)87 heightToStop int6488 }{89 {"empty block",90 func(stateDB dbm.DB, cs *ConsensusState, ctx context.Context) {},91 1},92 {"block with a smaller part size",93 func(stateDB dbm.DB, cs *ConsensusState, ctx context.Context) {94 // XXX: is there a better way to change BlockPartSizeBytes?95 cs.state.ConsensusParams.BlockPartSizeBytes = 51296 sm.SaveState(stateDB, cs.state)97 go sendTxs(cs, ctx)98 },99 1},100 {"many non-empty blocks",101 func(stateDB dbm.DB, cs *ConsensusState, ctx context.Context) {102 go sendTxs(cs, ctx)103 },104 3},105 }106 for _, tc := range testCases {107 t.Run(tc.name, func(t *testing.T) {108 crashWALandCheckLiveness(t, tc.initFn, tc.heightToStop)109 })110 }111}112func crashWALandCheckLiveness(t *testing.T, initFn func(dbm.DB, *ConsensusState, context.Context), heightToStop int64) {113 walPaniced := make(chan error)114 crashingWal := &crashingWAL{panicCh: walPaniced, heightToStop: heightToStop}115 i := 1116LOOP:117 for {118 // fmt.Printf("====== LOOP %d\n", i)119 t.Logf("====== LOOP %d\n", i)120 // create consensus state from a clean slate121 logger := log.NewNopLogger()122 stateDB := dbm.NewMemDB()123 state, _ := sm.MakeGenesisStateFromFile(consensusReplayConfig.GenesisFile())124 privValidator := loadPrivValidator(consensusReplayConfig)125 blockDB := dbm.NewMemDB()126 cs := newConsensusStateWithConfigAndBlockStore(consensusReplayConfig, state, privValidator, kvstore.NewKVStoreApplication(), blockDB)127 cs.SetLogger(logger)128 // start sending transactions129 ctx, cancel := context.WithCancel(context.Background())130 initFn(stateDB, cs, ctx)131 // clean up WAL file from the previous iteration132 walFile := cs.config.WalFile()133 os.Remove(walFile)134 // set crashing WAL135 csWal, err := cs.OpenWAL(walFile)136 require.NoError(t, err)137 crashingWal.next = csWal138 // reset the message counter139 crashingWal.msgIndex = 1140 cs.wal = crashingWal141 // start consensus state142 err = cs.Start()143 require.NoError(t, err)144 i++145 select {146 case err := <-walPaniced:147 t.Logf("WAL paniced: %v", err)148 // make sure we can make blocks after a crash149 startNewConsensusStateAndWaitForBlock(t, cs.Height, blockDB, stateDB)150 // stop consensus state and transactions sender (initFn)151 cs.Stop()152 cancel()153 // if we reached the required height, exit154 if _, ok := err.(ReachedHeightToStopError); ok {155 break LOOP156 }157 case <-time.After(10 * time.Second):158 t.Fatal("WAL did not panic for 10 seconds (check the log)")159 }160 }161}162// crashingWAL is a WAL which crashes or rather simulates a crash during Save163// (before and after). It remembers a message for which we last panicked164// (lastPanicedForMsgIndex), so we don't panic for it in subsequent iterations.165type crashingWAL struct {166 next WAL167 panicCh chan error168 heightToStop int64169 msgIndex int // current message index170 lastPanicedForMsgIndex int // last message for which we panicked171}172// WALWriteError indicates a WAL crash.173type WALWriteError struct {174 msg string175}176func (e WALWriteError) Error() string {177 return e.msg178}179// ReachedHeightToStopError indicates we've reached the required consensus180// height and may exit.181type ReachedHeightToStopError struct {182 height int64183}184func (e ReachedHeightToStopError) Error() string {185 return fmt.Sprintf("reached height to stop %d", e.height)186}187// Write simulate WAL's crashing by sending an error to the panicCh and then188// exiting the cs.receiveRoutine.189func (w *crashingWAL) Write(m WALMessage) {190 if endMsg, ok := m.(EndHeightMessage); ok {191 if endMsg.Height == w.heightToStop {192 w.panicCh <- ReachedHeightToStopError{endMsg.Height}193 runtime.Goexit()194 } else {195 w.next.Write(m)196 }197 return198 }199 if w.msgIndex > w.lastPanicedForMsgIndex {200 w.lastPanicedForMsgIndex = w.msgIndex201 _, file, line, _ := runtime.Caller(1)202 w.panicCh <- WALWriteError{fmt.Sprintf("failed to write %T to WAL (fileline: %s:%d)", m, file, line)}203 runtime.Goexit()204 } else {205 w.msgIndex++206 w.next.Write(m)207 }208}209func (w *crashingWAL) WriteSync(m WALMessage) {210 w.Write(m)211}212func (w *crashingWAL) Group() *auto.Group { return w.next.Group() }213func (w *crashingWAL) SearchForEndHeight(height int64, options *WALSearchOptions) (gr *auto.GroupReader, found bool, err error) {214 return w.next.SearchForEndHeight(height, options)215}216func (w *crashingWAL) Start() error { return w.next.Start() }217func (w *crashingWAL) Stop() error { return w.next.Stop() }218func (w *crashingWAL) Wait() { w.next.Wait() }219//------------------------------------------------------------------------------------------220// Handshake Tests221const (222 NUM_BLOCKS = 6223)224var (225 mempool = sm.MockMempool{}226 evpool = sm.MockEvidencePool{}227)228//---------------------------------------229// Test handshake/replay230// 0 - all synced up231// 1 - saved block but app and state are behind232// 2 - save block and committed but state is behind...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

...207 )208 mempoolLogger := logger.With("module", "mempool")209 mempoolReactor := mempl.NewReactor(config.Mempool, mempool)210 mempoolReactor.SetLogger(mempoolLogger)211 if config.Consensus.WaitForTxs() {212 mempool.EnableTxsAvailable()213 }214 return mempoolReactor, mempool215}...

Full Screen

Full Screen

Wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 proxyapp := &ProxyApp{}4 proxyapp.Start()5 proxyapp.Wait()6 fmt.Println("Exiting")7}8import (9func main() {10 proxyapp := &ProxyApp{}11 proxyapp.Start()12 proxyapp.Wait()13 fmt.Println("Exiting")14}15import (16func main() {17 proxyapp := &ProxyApp{}18 proxyapp.Start()19 proxyapp.Wait()20 fmt.Println("Exiting")21}22import (23func main() {24 proxyapp := &ProxyApp{}25 proxyapp.Start()26 proxyapp.Wait()27 fmt.Println("Exiting")28}29import (30func main() {31 proxyapp := &ProxyApp{}32 proxyapp.Start()33 proxyapp.Wait()34 fmt.Println("Exiting")35}36import (37func main() {38 proxyapp := &ProxyApp{}39 proxyapp.Start()40 proxyapp.Wait()41 fmt.Println("Exiting")42}43import (44func main() {45 proxyapp := &ProxyApp{}46 proxyapp.Start()47 proxyapp.Wait()48 fmt.Println("Exiting")49}50import (51func main() {52 proxyapp := &ProxyApp{}53 proxyapp.Start()54 proxyapp.Wait()55 fmt.Println("Exiting")56}57import (58func main() {59 proxyapp := &ProxyApp{}60 proxyapp.Start()61 proxyapp.Wait()62 fmt.Println("Exiting")63}

Full Screen

Full Screen

Wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := NewProxyApp()4 p.Start()5 time.Sleep(time.Second * 1)6 p.Stop()7 fmt.Scanln()8}9import (10func main() {11 p := NewProxyApp()12 p.Start()13 time.Sleep(time.Second * 1)14 p.Stop()15 p.Wait()16}

Full Screen

Full Screen

Wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("main started")4 proxy := NewProxyApp()5 go proxy.Start()6 go proxy.Stop()7 time.Sleep(2 * time.Second)8 fmt.Println("main stopped")9}10import (11func main() {12 fmt.Println("main started")13 proxy := NewProxyApp()14 go proxy.Start()15 go proxy.Stop()16 time.Sleep(2 * time.Second)17 fmt.Println("main stopped")18}19import (20func main() {21 fmt.Println("main started")22 proxy := NewProxyApp()23 go proxy.Start()24 go proxy.Stop()25 time.Sleep(2 * time.Second)26 fmt.Println("main stopped")27}28import (29func main() {30 fmt.Println("main started")31 proxy := NewProxyApp()32 go proxy.Start()33 go proxy.Stop()34 time.Sleep(2 * time.Second)35 fmt.Println("main stopped")36}37import (38func main() {39 fmt.Println("main started")40 proxy := NewProxyApp()41 go proxy.Start()42 go proxy.Stop()43 time.Sleep(2 * time.Second)44 fmt.Println("main stopped")45}46import (47func main() {48 fmt.Println("main started")49 proxy := NewProxyApp()50 go proxy.Start()51 go proxy.Stop()52 time.Sleep(2 * time.Second)53 fmt.Println("main stopped")54}55import (56func main() {57 fmt.Println("main started")58 proxy := NewProxyApp()

Full Screen

Full Screen

Wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 proxy := NewProxyApp()4 log.Println("Starting proxy...")5 proxy.Start()6 log.Println("Proxy started")7 time.Sleep(2 * time.Second)8 log.Println("Stopping proxy...")9 proxy.Stop()10 log.Println("Proxy stopped")11}12import (13func main() {14 proxy := NewProxyApp()15 log.Println("Starting proxy...")16 proxy.Start()17 log.Println("Proxy started")18 time.Sleep(2 * time.Second)19 log.Println("Stopping proxy...")20 proxy.Stop()21 log.Println("Proxy stopped")22}23import (24func main() {25 proxy := NewProxyApp()26 log.Println("Starting proxy...")27 proxy.Start()28 log.Println("Proxy started")29 time.Sleep(2 * time.Second)30 log.Println("Stopping proxy...")31 proxy.Stop()32 log.Println("Proxy stopped")33}34import (35func main() {36 proxy := NewProxyApp()37 log.Println("Starting proxy...")38 proxy.Start()39 log.Println("Proxy started")40 time.Sleep(2 * time.Second)41 log.Println("Stopping proxy...")42 proxy.Stop()43 log.Println("Proxy stopped")44}45import (46func main() {47 proxy := NewProxyApp()48 log.Println("Starting proxy...")49 proxy.Start()50 log.Println("Proxy started")51 time.Sleep(2 * time.Second)52 log.Println("Stopping proxy...")53 proxy.Stop()54 log.Println("Proxy stopped")55}56import (57func main() {58 proxy := NewProxyApp()59 log.Println("Starting proxy...")60 proxy.Start()61 log.Println("Proxy started")62 time.Sleep(2

Full Screen

Full Screen

Wait

Using AI Code Generation

copy

Full Screen

1import "fmt"2type proxyapp struct {3}4func (p proxyapp) wait() {5 fmt.Println("waiting")6}7type app interface {8 wait()9}10func main() {11 p := proxyapp{}12 p.wait()13}

Full Screen

Full Screen

Wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := new(proxyapp)4 p.init()5 p.start()6 p.wait()7 fmt.Println("main: done")8}9import (10func main() {11 p := new(proxyapp)12 p.init()13 p.start()14 p.wait()15 fmt.Println("main: done")16}17import (18func main() {19 p := new(proxyapp)20 p.init()21 p.start()22 p.wait()23 fmt.Println("main: done")24}25import (26func main() {27 p := new(proxyapp)28 p.init()29 p.start()30 p.wait()31 fmt.Println("main: done")32}33import (34func main() {35 p := new(proxyapp)36 p.init()37 p.start()38 p.wait()39 fmt.Println("main: done")40}41import (42func main() {43 p := new(proxyapp)44 p.init()45 p.start()46 p.wait()47 fmt.Println("main: done")48}49import (50func main() {51 p := new(proxyapp)52 p.init()53 p.start()54 p.wait()55 fmt.Println("main: done")56}

Full Screen

Full Screen

Wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 proxyapp.StartProxyApp()4 fmt.Println("Proxy app started")5 proxyapp.Wait()6 fmt.Println("Proxy app stopped")7}

Full Screen

Full Screen

Wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := proxyapp.NewProxyApp()4 p.Run()5 p.Wait()6 fmt.Println("main: proxyapp exited")7}8import (9func main() {10 p := proxyapp.NewProxyApp()11 p.Run()12 p.Wait()13 fmt.Println("main: proxyapp exited")14}15import (16func main() {17 p := proxyapp.NewProxyApp()18 p.Run()19 p.Wait()20 fmt.Println("main: proxyapp exited")21}22import (23func main() {24 p := proxyapp.NewProxyApp()25 p.Run()26 p.Wait()27 fmt.Println("main: proxyapp exited")28}29import (30func main() {31 p := proxyapp.NewProxyApp()32 p.Run()33 p.Wait()34 fmt.Println("main: proxyapp exited")35}36import (37func main() {38 p := proxyapp.NewProxyApp()39 p.Run()40 p.Wait()41 fmt.Println("main: proxyapp exited")42}43import (44func main() {45 p := proxyapp.NewProxyApp()46 p.Run()47 p.Wait()48 fmt.Println("main: proxyapp exited")49}50import (51func main() {52 p := proxyapp.NewProxyApp()53 p.Run()54 p.Wait()55 fmt.Println("main: proxyapp exited")56}57import (58func main() {

Full Screen

Full Screen

Wait

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 p := proxyapp{0}4 p.Start()5 p.Wait()6 fmt.Println("Proxyapp is done!")7}8import "fmt"9func main() {10 p := proxyapp{0}11 p.Start()12 p.Wait()13 fmt.Println("Proxyapp is done!")14}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful