Remove unconditional nil Error setting. #5341

Merged
merged 1 commit into from May 5, 2016
Jump to file or symbol
Failed to load files and symbols.
+27 −14
Split
@@ -55,12 +55,13 @@ func (api *ProxyUpdaterAPI) oneWatch() params.NotifyWatchResult {
result = params.NotifyWatchResult{
NotifyWatcherId: api.resources.Register(watch),
}
+ } else {
+ result.Error = common.ServerError(watcher.EnsureErr(watch))
}
- result.Error = common.ServerError(watcher.EnsureErr(watch))
return result
}
-// WatchChanges watches for cleanups to be perfomed in state
+// WatchForProxyConfigAndAPIHostPortChanges watches for cleanups to be perfomed in state
func (api *ProxyUpdaterAPI) WatchForProxyConfigAndAPIHostPortChanges(args params.Entities) params.NotifyWatchResults {
results := params.NotifyWatchResults{
Results: make([]params.NotifyWatchResult, len(args.Entities)),
@@ -70,8 +71,9 @@ func (api *ProxyUpdaterAPI) WatchForProxyConfigAndAPIHostPortChanges(args params
for i := range args.Entities {
if errors.Results[i].Error == nil {
results.Results[i] = api.oneWatch()
+ } else {
+ results.Results[i].Error = errors.Results[i].Error
}
- results.Results[i].Error = errors.Results[i].Error
}
return results
@@ -4,6 +4,8 @@
package proxyupdater_test
import (
+ "time"
+
"github.com/juju/names"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
@@ -15,7 +17,6 @@ import (
"github.com/juju/juju/environs/config"
"github.com/juju/juju/network"
"github.com/juju/juju/state"
- statetesting "github.com/juju/juju/state/testing"
coretesting "github.com/juju/juju/testing"
"github.com/juju/juju/worker/workertest"
"github.com/juju/testing"
@@ -64,17 +65,27 @@ func (s *ProxyUpdaterSuite) SetUpTest(c *gc.C) {
func (s *ProxyUpdaterSuite) TestWatchForProxyConfigAndAPIHostPortChanges(c *gc.C) {
// WatchForProxyConfigAndAPIHostPortChanges combines WatchForModelConfigChanges
// and WatchAPIHostPorts. Check that they are both called and we get the
- s.facade.WatchForProxyConfigAndAPIHostPortChanges(s.oneEntity())
-
- // Verify the watcher resource was registered.
- c.Assert(s.resources.Count(), gc.Equals, 1)
- resource := s.resources.Get("1")
- defer statetesting.AssertStop(c, resource)
+ result := s.facade.WatchForProxyConfigAndAPIHostPortChanges(s.oneEntity())
+ c.Assert(result.Results, gc.HasLen, 1)
+ c.Assert(result.Results[0].Error, gc.IsNil)
s.state.Stub.CheckCallNames(c,
"WatchForModelConfigChanges",
"WatchAPIHostPorts",
)
+
+ // Verify the watcher resource was registered.
+ c.Assert(s.resources.Count(), gc.Equals, 1)
+ resource := s.resources.Get(result.Results[0].NotifyWatcherId)
+ watcher, ok := resource.(state.NotifyWatcher)
+ c.Assert(ok, jc.IsTrue)
+
+ // Verify the initial event was consumed.
+ select {
+ case <-watcher.Changes():
+ c.Fatalf("initial event never consumed")
+ case <-time.After(coretesting.ShortWait):
+ }
}
func (s *ProxyUpdaterSuite) oneEntity() params.Entities {
@@ -168,8 +179,8 @@ func (sb *stubBackend) SetUp(c *gc.C) {
"http-proxy": "http proxy",
"https-proxy": "https proxy",
}
- sb.hpWatcher = workertest.NewFakeWatcher(2, 2)
- sb.confWatcher = workertest.NewFakeWatcher(2, 2)
+ sb.hpWatcher = workertest.NewFakeWatcher(1, 1)
+ sb.confWatcher = workertest.NewFakeWatcher(1, 1)
}
func (sb *stubBackend) Kill() {
@@ -37,9 +37,9 @@ func Stop(w Stopper, t *tomb.Tomb) {
func EnsureErr(w Errer) error {
err := w.Err()
if err == nil {
- return errors.Errorf("expected an error from %#v, got nil", w)
+ return errors.Errorf("expected an error from %v, got nil", w)
} else if err == tomb.ErrStillAlive {
- return errors.Annotatef(err, "expected %#v to be stopped", w)
+ return errors.Annotatef(err, "expected %v to be stopped", w)
}
return errors.Trace(err)
}