Skip to content

Commit

Permalink
Move plugin start calls to namespace manager
Browse files Browse the repository at this point in the history
Avoid starting plugins more than once.

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
  • Loading branch information
awrichar committed Jun 28, 2022
1 parent e64eafc commit d894817
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 47 deletions.
10 changes: 10 additions & 0 deletions internal/namespace/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ func (nm *namespaceManager) Start() error {
metrics.Registry()
}
for _, ns := range nm.namespaces {
if ns.plugins.Blockchain.Plugin != nil {
if err := ns.plugins.Blockchain.Plugin.Start(); err != nil {
return err
}
}
for _, plugin := range ns.plugins.Tokens {
if err := plugin.Plugin.Start(); err != nil {
return err
}
}
if err := ns.orchestrator.Start(); err != nil {
return err
}
Expand Down
10 changes: 0 additions & 10 deletions internal/orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,22 +269,12 @@ func (or *orchestrator) Start() (err error) {
err = or.sharedDownload.Start()
}
}
if err == nil {
err = or.blockchain().Start()
}
if err == nil {
err = or.events.Start()
}
if err == nil {
err = or.operations.Start()
}
if err == nil {
for _, el := range or.tokens() {
if err = el.Start(); err != nil {
break
}
}
}
or.started = true
return err
}
Expand Down
37 changes: 0 additions & 37 deletions internal/orchestrator/orchestrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,41 +379,6 @@ func TestStartBatchFail(t *testing.T) {
assert.EqualError(t, err, "pop")
}

func TestStartTokensFail(t *testing.T) {
coreconfig.Reset()
or := newTestOrchestrator()
defer or.cleanup(t)
or.mdi.On("GetNamespace", mock.Anything, "ns").Return(nil, nil)
or.mdi.On("UpsertNamespace", mock.Anything, mock.Anything, true).Return(nil)
or.mmp.On("ConfigureContract", mock.Anything, &core.FireFlyContracts{}).Return(nil)
or.mbi.On("Start").Return(nil)
or.mba.On("Start").Return(nil)
or.mem.On("Start").Return(nil)
or.mbm.On("Start").Return(nil)
or.mpm.On("Start").Return(nil)
or.msd.On("Start").Return(nil)
or.mom.On("Start").Return(nil)
or.mti.On("Start").Return(fmt.Errorf("pop"))
err := or.Start()
assert.EqualError(t, err, "pop")
}

func TestStartBlockchainsFail(t *testing.T) {
coreconfig.Reset()
or := newTestOrchestrator()
defer or.cleanup(t)
or.mdi.On("GetNamespace", mock.Anything, "ns").Return(nil, nil)
or.mdi.On("UpsertNamespace", mock.Anything, mock.Anything, true).Return(nil)
or.mmp.On("ConfigureContract", mock.Anything, &core.FireFlyContracts{}).Return(nil)
or.mbm.On("Start").Return(nil)
or.mpm.On("Start").Return(nil)
or.mba.On("Start").Return(nil)
or.msd.On("Start").Return(nil)
or.mbi.On("Start").Return(fmt.Errorf("pop"))
err := or.Start()
assert.EqualError(t, err, "pop")
}

func TestStartBlockchainsConfigureFail(t *testing.T) {
coreconfig.Reset()
or := newTestOrchestrator()
Expand All @@ -431,12 +396,10 @@ func TestStartStopOk(t *testing.T) {
or.mdi.On("GetNamespace", mock.Anything, "ns").Return(nil, nil)
or.mdi.On("UpsertNamespace", mock.Anything, mock.Anything, true).Return(nil)
or.mmp.On("ConfigureContract", mock.Anything, &core.FireFlyContracts{}).Return(nil)
or.mbi.On("Start").Return(nil)
or.mba.On("Start").Return(nil)
or.mem.On("Start").Return(nil)
or.mbm.On("Start").Return(nil)
or.mpm.On("Start").Return(nil)
or.mti.On("Start").Return(nil)
or.msd.On("Start").Return(nil)
or.mom.On("Start").Return(nil)
or.mba.On("WaitStop").Return(nil)
Expand Down

0 comments on commit d894817

Please sign in to comment.