Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Add load method to retry loading of a plugin for travis issues
Browse files Browse the repository at this point in the history
  • Loading branch information
geauxvirtual committed Oct 29, 2015
1 parent da78c23 commit 06e96e8
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions control/plugin_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/intelsdi-x/pulse/control/plugin"
"github.com/intelsdi-x/pulse/core/ctypes"
"github.com/intelsdi-x/pulse/core/perror"
)

var (
Expand Down Expand Up @@ -70,6 +71,25 @@ func TestLoadedPlugins(t *testing.T) {
})
}

func loadPlugin(p *pluginManager, path string) (*loadedPlugin, perror.PulseError) {
// This is a Travis optimized loading of plugins. From time to time, tests will error in Travis
// due to a timeout when waiting for a response from a plugin. We are going to attempt loading a plugin
// 3 times before letting the error through. Hopefully this cuts down on the number of Travis failures
var e perror.PulseError
var lp *loadedPlugin
for i := 0; i < 3; i++ {
lp, e = p.LoadPlugin(path, nil)
if e == nil {
break
}
if e != nil && i == 2 {
return nil, e

}
}
return lp, nil
}

// Uses the dummy collector plugin to simulate loading
func TestLoadPlugin(t *testing.T) {
// These tests only work if PULSE_PATH is known
Expand All @@ -82,7 +102,7 @@ func TestLoadPlugin(t *testing.T) {
Convey("loads plugin successfully", func() {
p := newPluginManager()
p.SetMetricCatalog(newMetricCatalog())
lp, err := p.LoadPlugin(PluginPath, nil)
lp, err := loadPlugin(p, PluginPath)

So(lp, ShouldHaveSameTypeAs, new(loadedPlugin))
So(p.all(), ShouldNotBeEmpty)
Expand All @@ -95,7 +115,7 @@ func TestLoadPlugin(t *testing.T) {
cfg.Plugins.Collector.Plugins["dummy2"] = newPluginConfigItem(optAddPluginConfigItem("test", ctypes.ConfigValueBool{Value: true}))
p := newPluginManager(OptSetPluginConfig(cfg.Plugins))
p.SetMetricCatalog(newMetricCatalog())
lp, err := p.LoadPlugin(PluginPath, nil)
lp, err := loadPlugin(p, PluginPath)

So(lp, ShouldHaveSameTypeAs, new(loadedPlugin))
So(p.all(), ShouldNotBeEmpty)
Expand All @@ -111,7 +131,7 @@ func TestLoadPlugin(t *testing.T) {
cfg.Plugins.Collector.Plugins["dummy2"] = newPluginConfigItem(optAddPluginConfigItem("test-fail", ctypes.ConfigValueBool{Value: true}))
p := newPluginManager(OptSetPluginConfig(cfg.Plugins))
p.SetMetricCatalog(newMetricCatalog())
lp, err := p.LoadPlugin(PluginPath, nil)
lp, err := loadPlugin(p, PluginPath)

So(lp, ShouldBeNil)
So(p.all(), ShouldBeEmpty)
Expand All @@ -123,7 +143,7 @@ func TestLoadPlugin(t *testing.T) {
Convey("loads json-rpc plugin successfully", func() {
p := newPluginManager()
p.SetMetricCatalog(newMetricCatalog())
lp, err := p.LoadPlugin(JSONRPC_PluginPath, nil)
lp, err := loadPlugin(p, JSONRPC_PluginPath)

So(lp, ShouldHaveSameTypeAs, new(loadedPlugin))
So(p.loadedPlugins, ShouldNotBeEmpty)
Expand All @@ -134,21 +154,13 @@ func TestLoadPlugin(t *testing.T) {
Convey("loads plugin with cache TTL set", func() {
p := newPluginManager()
p.SetMetricCatalog(newMetricCatalog())
lp, err := p.LoadPlugin(JSONRPC_PluginPath, nil)
lp, err := loadPlugin(p, JSONRPC_PluginPath)

So(err, ShouldBeNil)
So(lp.Meta.CacheTTL, ShouldNotBeNil)
So(lp.Meta.CacheTTL, ShouldResemble, time.Duration(time.Millisecond*100))
})

// Convey("error is returned on a bad PluginPath", func() {
// p := newPluginManager()
// lp, err := p.LoadPlugin("", nil)

// So(lp, ShouldBeNil)
// So(err, ShouldNotBeNil)
// })

})

}
Expand All @@ -162,7 +174,7 @@ func TestUnloadPlugin(t *testing.T) {
Convey("then it is removed from the loadedPlugins", func() {
p := newPluginManager()
p.SetMetricCatalog(newMetricCatalog())
_, err := p.LoadPlugin(PluginPath, nil)
_, err := loadPlugin(p, PluginPath)
So(err, ShouldBeNil)

numPluginsLoaded := len(p.all())
Expand All @@ -179,7 +191,7 @@ func TestUnloadPlugin(t *testing.T) {
Convey("then an error is thrown", func() {
p := newPluginManager()
p.SetMetricCatalog(newMetricCatalog())
lp, err := p.LoadPlugin(PluginPath, nil)
lp, err := loadPlugin(p, PluginPath)
glp, err2 := p.get("collector:dummy2:2")
So(err2, ShouldBeNil)
glp.State = DetectedState
Expand All @@ -192,7 +204,7 @@ func TestUnloadPlugin(t *testing.T) {
Convey("then an error is thrown", func() {
p := newPluginManager()
p.SetMetricCatalog(newMetricCatalog())
_, err := p.LoadPlugin(PluginPath, nil)
_, err := loadPlugin(p, PluginPath)

lp, err2 := p.get("collector:dummy2:2")
So(err2, ShouldBeNil)
Expand Down

0 comments on commit 06e96e8

Please sign in to comment.