Skip to content
Snippets Groups Projects
Commit e4447dbd authored by Wolfgang Welz's avatar Wolfgang Welz
Browse files

fix: run all bundle processor tests as sub tests

parent 254815d9
No related branches found
No related tags found
No related merge requests found
......@@ -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()
}
......@@ -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")
})
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment