consul: always fire events from server nodes

This commit is contained in:
Ryan Uber 2015-06-18 16:20:24 -07:00
parent 6e9adae494
commit e6923a4832
3 changed files with 12 additions and 28 deletions

View File

@ -85,16 +85,15 @@ func (a *Agent) UserEvent(dc, token string, params *UserEvent) error {
return fmt.Errorf("UserEvent encoding failed: %v", err)
}
// Send an RPC to service this
// Service the event fire over RPC. This ensures that we authorize
// the request against the token first.
args := structs.EventFireRequest{
Datacenter: dc,
Name: params.Name,
Payload: payload,
Datacenter: dc,
Name: params.Name,
Payload: payload,
QueryOptions: structs.QueryOptions{Token: token},
}
// Pass along the ACL token, if any
args.Token = token
// Any server can process in the remote DC, since the
// gossip will take over anyways
args.AllowStale = true

View File

@ -201,11 +201,6 @@ func (c *Client) RemoveFailedNode(node string) error {
return c.serf.RemoveFailedNode(node)
}
// UserEvent is used to fire an event via the Serf layer
func (c *Client) UserEvent(name string, payload []byte) error {
return c.serf.UserEvent(userEventName(name), payload, false)
}
// KeyManagerLAN returns the LAN Serf keyring manager
func (c *Client) KeyManagerLAN() *serf.KeyManager {
return c.serf.KeyManager()

View File

@ -276,26 +276,18 @@ func TestClientServer_UserEvent(t *testing.T) {
})
// Fire the user event
err := c1.UserEvent("foo", []byte("bar"))
if err != nil {
t.Fatalf("err: %v", err)
}
err = s1.UserEvent("bar", []byte("baz"))
if err != nil {
if err := s1.UserEvent("foo", []byte("baz")); err != nil {
t.Fatalf("err: %v", err)
}
// Wait for all the events
var serverFoo, serverBar, clientFoo, clientBar bool
for i := 0; i < 4; i++ {
var clientReceived, serverReceived bool
for i := 0; i < 2; i++ {
select {
case e := <-clientOut:
switch e.Name {
case "foo":
clientFoo = true
case "bar":
clientBar = true
clientReceived = true
default:
t.Fatalf("Bad: %#v", e)
}
@ -303,9 +295,7 @@ func TestClientServer_UserEvent(t *testing.T) {
case e := <-serverOut:
switch e.Name {
case "foo":
serverFoo = true
case "bar":
serverBar = true
serverReceived = true
default:
t.Fatalf("Bad: %#v", e)
}
@ -315,7 +305,7 @@ func TestClientServer_UserEvent(t *testing.T) {
}
}
if !(serverFoo && serverBar && clientFoo && clientBar) {
if !serverReceived || !clientReceived {
t.Fatalf("missing events")
}
}