From e4447dbdf4760a4c0bee76e28d424d0fe438ecea Mon Sep 17 00:00:00 2001 From: Wolfgang Welz <welzwo@gmail.com> Date: Wed, 8 Jan 2020 19:33:30 +0100 Subject: [PATCH] fix: run all bundle processor tests as sub tests --- .../bundleprocessor/bundleprocessor_test.go | 96 +++++++++---------- plugins/bundleprocessor/plugin.go | 8 +- 2 files changed, 48 insertions(+), 56 deletions(-) diff --git a/plugins/bundleprocessor/bundleprocessor_test.go b/plugins/bundleprocessor/bundleprocessor_test.go index 484d6a29..5b78beae 100644 --- a/plugins/bundleprocessor/bundleprocessor_test.go +++ b/plugins/bundleprocessor/bundleprocessor_test.go @@ -65,74 +65,66 @@ func TestValidateSignatures(t *testing.T) { assert.Equal(t, successful, true, "validation failed") } -func TestProcessSolidBundleHead_Data(t *testing.T) { +func TestProcessSolidBundleHead(t *testing.T) { // start a test node node.Start(node.Plugins(tangle.PLUGIN, PLUGIN)) defer node.Shutdown() - bundleFactory := client.NewBundleFactory() - bundleFactory.AddOutput(seed.GetAddress(1), 400, "Testmessage") - bundleFactory.AddOutput(client.NewAddress("SJKUKQP9SWUSUCPRQXCMDVDVZ9SHHESHIQNCXWBJF9UJSWE9ZYFHQWAUPCXC9S9DSHP9NDF9RLNPMZVCM"), 400, "Testmessage") + t.Run("data", func(t *testing.T) { + bundleFactory := client.NewBundleFactory() + bundleFactory.AddOutput(seed.GetAddress(1), 400, "Testmessage") + bundleFactory.AddOutput(client.NewAddress("SJKUKQP9SWUSUCPRQXCMDVDVZ9SHHESHIQNCXWBJF9UJSWE9ZYFHQWAUPCXC9S9DSHP9NDF9RLNPMZVCM"), 400, "Testmessage") - generatedBundle := bundleFactory.GenerateBundle(tipselection.GetRandomTip(), tipselection.GetRandomTip()) + generatedBundle := bundleFactory.GenerateBundle(tipselection.GetRandomTip(), tipselection.GetRandomTip()) + for _, transaction := range generatedBundle.GetTransactions() { + tangle.StoreTransaction(transaction) + } - for _, transaction := range generatedBundle.GetTransactions() { - tangle.StoreTransaction(transaction) - } + var wg sync.WaitGroup + testResults := events.NewClosure(func(bundle *bundle.Bundle, transactions []*value_transaction.ValueTransaction) { + assert.Equal(t, bundle.GetHash(), generatedBundle.GetTransactions()[0].GetHash(), "invalid bundle hash") + assert.Equal(t, bundle.IsValueBundle(), false, "invalid value bundle status") - var wg sync.WaitGroup + wg.Done() + }) + Events.BundleSolid.Attach(testResults) + defer Events.BundleSolid.Detach(testResults) - testResults := events.NewClosure(func(bundle *bundle.Bundle, transactions []*value_transaction.ValueTransaction) { - assert.Equal(t, bundle.GetHash(), generatedBundle.GetTransactions()[0].GetHash(), "invalid bundle hash") - assert.Equal(t, bundle.IsValueBundle(), false, "invalid value bundle status") + wg.Add(1) + if err := ProcessSolidBundleHead(generatedBundle.GetTransactions()[0]); err != nil { + t.Error(err) + } - wg.Done() + wg.Wait() }) - Events.BundleSolid.Attach(testResults) - defer Events.BundleSolid.Detach(testResults) - - wg.Add(1) - if err := ProcessSolidBundleHead(generatedBundle.GetTransactions()[0]); err != nil { - t.Error(err) - } - - wg.Wait() -} - -func TestProcessSolidBundleHead_Value(t *testing.T) { - // start a test node - node.Start(node.Plugins(tangle.PLUGIN, PLUGIN)) - defer node.Shutdown() + t.Run("value", func(t *testing.T) { + bundleFactory := client.NewBundleFactory() + bundleFactory.AddInput(seed.GetAddress(0), -400) + bundleFactory.AddOutput(seed.GetAddress(1), 400, "Testmessage") + bundleFactory.AddOutput(client.NewAddress("SJKUKQP9SWUSUCPRQXCMDVDVZ9SHHESHIQNCXWBJF9UJSWE9ZYFHQWAUPCXC9S9DSHP9NDF9RLNPMZVCM"), 400, "Testmessage") - bundleFactory := client.NewBundleFactory() - bundleFactory.AddInput(seed.GetAddress(0), -400) - bundleFactory.AddOutput(seed.GetAddress(1), 400, "Testmessage") - bundleFactory.AddOutput(client.NewAddress("SJKUKQP9SWUSUCPRQXCMDVDVZ9SHHESHIQNCXWBJF9UJSWE9ZYFHQWAUPCXC9S9DSHP9NDF9RLNPMZVCM"), 400, "Testmessage") + generatedBundle := bundleFactory.GenerateBundle(tipselection.GetRandomTip(), tipselection.GetRandomTip()) + for _, transaction := range generatedBundle.GetTransactions() { + tangle.StoreTransaction(transaction) + } - generatedBundle := bundleFactory.GenerateBundle(tipselection.GetRandomTip(), tipselection.GetRandomTip()) + var wg sync.WaitGroup + testResults := events.NewClosure(func(bundle *bundle.Bundle, transactions []*value_transaction.ValueTransaction) { + assert.Equal(t, bundle.GetHash(), generatedBundle.GetTransactions()[0].GetHash(), "invalid bundle hash") + assert.Equal(t, bundle.IsValueBundle(), true, "invalid value bundle status") - for _, transaction := range generatedBundle.GetTransactions() { - tangle.StoreTransaction(transaction) - } + wg.Done() + }) - var wg sync.WaitGroup + wg.Add(1) + Events.BundleSolid.Attach(testResults) + defer Events.BundleSolid.Detach(testResults) - testResults := events.NewClosure(func(bundle *bundle.Bundle, transactions []*value_transaction.ValueTransaction) { - assert.Equal(t, bundle.GetHash(), generatedBundle.GetTransactions()[0].GetHash(), "invalid bundle hash") - assert.Equal(t, bundle.IsValueBundle(), true, "invalid value bundle status") + if err := ProcessSolidBundleHead(generatedBundle.GetTransactions()[0]); err != nil { + t.Error(err) + } - wg.Done() + wg.Wait() }) - - Events.BundleSolid.Attach(testResults) - defer Events.BundleSolid.Detach(testResults) - - wg.Add(1) - - if err := ProcessSolidBundleHead(generatedBundle.GetTransactions()[0]); err != nil { - t.Error(err) - } - - wg.Wait() } diff --git a/plugins/bundleprocessor/plugin.go b/plugins/bundleprocessor/plugin.go index c95eeeed..b3697715 100644 --- a/plugins/bundleprocessor/plugin.go +++ b/plugins/bundleprocessor/plugin.go @@ -13,7 +13,7 @@ import ( var PLUGIN = node.NewPlugin("Bundle Processor", node.Enabled, configure, run) var log = logger.NewLogger("Bundle Processor") -func configure(plugin *node.Plugin) { +func configure(*node.Plugin) { tangle.Events.TransactionSolid.Attach(events.NewClosure(func(tx *value_transaction.ValueTransaction) { if tx.IsHead() { workerPool.Submit(tx) @@ -25,7 +25,7 @@ func configure(plugin *node.Plugin) { })) } -func run(plugin *node.Plugin) { +func run(*node.Plugin) { log.Info("Starting Bundle Processor ...") daemon.BackgroundWorker("Bundle Processor", func(shutdownSignal <-chan struct{}) { @@ -33,7 +33,7 @@ func run(plugin *node.Plugin) { workerPool.Start() <-shutdownSignal log.Info("Stopping Bundle Processor ...") - workerPool.Stop() + workerPool.StopAndWait() log.Info("Stopping Bundle Processor ... done") }) @@ -44,7 +44,7 @@ func run(plugin *node.Plugin) { valueBundleProcessorWorkerPool.Start() <-shutdownSignal log.Info("Stopping Value Bundle Processor ...") - valueBundleProcessorWorkerPool.Stop() + valueBundleProcessorWorkerPool.StopAndWait() log.Info("Stopping Value Bundle Processor ... done") }) } -- GitLab