Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix problem with Campfire hook notifying on start. #36

Merged
merged 4 commits into from

3 participants

@roidrage
Owner

Also start on a more higher-level spec for the notifications system in general. A work in progress. This fixes the problems caused by #34.

@roidrage roidrage Fix problem with Campfire hook notifying on start.
Also start on a more higher-level spec for the notifications
system in general. A work in progress.
f3e268c
lib/travis/notifications/handler/campfire.rb
@@ -35,6 +36,7 @@ def build_url(build)
end
def notify(event, object, *args)
+ puts 'boom'

That's not left on purpose right ? :)

@roidrage Owner

Haha, no! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dmathieu

Thank you for the global notifications specs. That's awesome :heart:

@dmathieu

I believe it's possible to add a test checking for this regression.

@roidrage
Owner

For which regression? For "boom"? ;)

@dmathieu

No, for the regex which was missing.

@roidrage
Owner

Is there a test missing for this? I may have overlooked something.

@dmathieu

Oh I see, I overlooked the notifications_spec file.
Perhaps this is not the best place to put webhook and campfire notifications ?

There are campfire_spec and webhook_spec files.

@roidrage roidrage Instrument notifications with metrics.
Add first stab at a test suite for the subscription class.
676a4ee
@roidrage
Owner

The reason I added this more higher-level test is because the campfire spec can't really test if an event is not triggered when the event doesn't match, that happens when a subscription is triggered. What it could do is make sure EVENTS only contains build:finished. That's certainly up for arguments, but I also started the test for notifications in general, because the whole system is lacking more higher level means of testing.

@roidrage roidrage Add explicit tests about what the EVENTS constants.
More explicit tests for the correct event subscriptions.
3b17b67
@roidrage
Owner

Okay, added some more explicit tests for the EVENTS constant. This should make sure something like this doesn't come up on several levels :)

@dmathieu

Thank you :)

@dmathieu dmathieu merged commit 3e5b061 into master
@joshk
Owner

Hey @dmathieu,

Was this fix tested on Staging before being merged in?

We are trying to be a little more cautious about merging in PRs, the main goal is to first test on staging and then merge in.

I think it is also good to comment on the PR asking if it is ready for merging and ready to be tested on staging, using the PR more as a discussion then just a way to contribute code.

Let me know if you have any questions/comments about this.

Thanks a bundle,

Josh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 28, 2012
  1. @roidrage

    Fix problem with Campfire hook notifying on start.

    roidrage authored
    Also start on a more higher-level spec for the notifications
    system in general. A work in progress.
  2. @roidrage

    Boom!

    roidrage authored
Commits on Mar 29, 2012
  1. @roidrage

    Instrument notifications with metrics.

    roidrage authored
    Add first stab at a test suite for the subscription class.
  2. @roidrage

    Add explicit tests about what the EVENTS constants.

    roidrage authored
    More explicit tests for the correct event subscriptions.
This page is out of date. Refresh to see the latest.
View
1  lib/travis/notifications/handler/campfire.rb
@@ -7,6 +7,7 @@ module Handler
#
# Campfire credentials are encrypted using the repository's ssl key.
class Campfire < Webhook
+ EVENTS = /build:finished/
class << self
def campfire_url(config)
View
12 lib/travis/notifications/subscription.rb
@@ -1,3 +1,5 @@
+require 'metriks'
+
module Travis
module Notifications
@@ -20,12 +22,20 @@ def initialize(name)
end
def notify(event, *args)
- subscriber.new.notify(event, *args) if matches?(event)
+ if matches?(event)
+ subscriber.new.notify(event, *args)
+ increment_counter(event)
+ end
end
def matches?(event)
patterns.any? { |patterns| patterns.is_a?(Regexp) ? patterns.match(event) : patterns == event }
end
+
+ def increment_counter(event)
+ metric = "travis.notifications.#{name}.#{event.gsub(/:/, '.')}"
+ Metriks.counter(metric).increment
+ end
}
end
end
View
5 spec/travis/notifications/handler/campfire_spec.rb
@@ -19,6 +19,11 @@
end
end
+ it "only is set up to accept build:finished notifications" do
+ Travis::Notifications::Handler::Campfire::EVENTS.should === 'build:finished'
+ Travis::Notifications::Handler::Campfire::EVENTS.should_not === 'build:started'
+ end
+
it "sends campfire notifications to the room given as a string" do
target = 'evome:apitoken@42'
build.config[:notifications][:campfire] = target
View
5 spec/travis/notifications/handler/webhook_spec.rb
@@ -20,6 +20,11 @@
end
end
+ it "only is set up to accept build:finished and build:started notifications" do
+ Travis::Notifications::Handler::Webhook::EVENTS.should === 'build:finished'
+ Travis::Notifications::Handler::Webhook::EVENTS.should === 'build:started'
+ end
+
it 'sends webhook notifications to a url given as a string' do
target = 'http://evome.fr/notifications'
build.config[:notifications][:webhooks] = target
View
43 spec/travis/notifications/subscription_spec.rb
@@ -0,0 +1,43 @@
+require 'spec_helper'
+require 'active_support/core_ext/class'
+
+describe Travis::Notifications::Subscription do
+ class Travis::Notifications::Handler::SubscriptionTestHandler
+ class_attribute :events
+ self.events = []
+
+ EVENTS = /build:finished/
+
+ def notify(*args)
+ self.class.notify(*args)
+ end
+
+ def self.notify(*args)
+ events << args
+ end
+ end
+
+ let(:subscription) {Travis::Notifications::Subscription.new(:subscription_test_handler)}
+
+ describe "triggering a notification" do
+ before do
+ subscription.subscriber.events.clear
+ end
+
+ it "should notify when the event matches" do
+ subscription.notify('build:finished')
+ subscription.subscriber.events.should have(1).item
+ end
+
+ it "should increment a counter when the event is triggered" do
+ expect {
+ subscription.notify('build:finished')
+ }.to change {Metriks.counter('travis.notifications.subscription_test_handler.build.finished').count}
+ end
+
+ it "shouldn't notify when the event doesn't match" do
+ subscription.notify('build:started')
+ subscription.subscriber.events.should have(0).items
+ end
+ end
+end
View
47 spec/travis/notifications_spec.rb
@@ -0,0 +1,47 @@
+require 'spec_helper'
+require 'support/active_record'
+
+# A more high-level test for notifications as a whole
+describe Travis::Notifications do
+ include Travis::Notifications
+ include Support::ActiveRecord
+
+ let(:build) { Factory(:build, :config => { 'notifications' => { 'campfire' => 'evome:apitoken@42' } }) }
+ describe "notifying of an event" do
+ describe "campfire" do
+ before do
+ Travis.config.notifications = [:campfire]
+ end
+
+ it "should not publish start events to campfire" do
+ Travis::Notifications::Handler::Campfire.any_instance.expects(:notify).never
+ notify("build:started", build)
+ end
+
+ it "should publish finish events to campfire" do
+ Travis::Notifications::Handler::Campfire.any_instance.expects(:notify)
+ notify("build:finished", build)
+ end
+ end
+
+ describe "webhooks" do
+ before do
+ Travis.config.notifications = [:webhook]
+ end
+
+ it "should publish start events to webhooks" do
+ targets = ['http://evome.fr/notifications', 'http://example.com/']
+ build.config[:notifications][:webhooks] = {:urls => targets}
+ Travis::Notifications::Handler::Webhook.any_instance.expects(:notify)
+ notify("build:started")
+ end
+
+ it "should publish finish events to webhooks" do
+ targets = ['http://evome.fr/notifications', 'http://example.com/']
+ build.config[:notifications][:webhooks] = {:urls => targets}
+ Travis::Notifications::Handler::Webhook.any_instance.expects(:notify)
+ notify("build:finish")
+ end
+ end
+ end
+end
Something went wrong with that request. Please try again.