summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-05-30 02:29:23 +0000
committerLuke Kanies <luke@madstop.com>2005-05-30 02:29:23 +0000
commit0ab9685383bc21d9903a06d62a01f6cb72d25610 (patch)
treead8d5dac1e252b2e5a056d5665a751f9737108e3
parent2b97b479688e987a8d9e663fd926108e7c02e7e4 (diff)
downloadpuppet-0ab9685383bc21d9903a06d62a01f6cb72d25610.tar.gz
puppet-0ab9685383bc21d9903a06d62a01f6cb72d25610.tar.xz
puppet-0ab9685383bc21d9903a06d62a01f6cb72d25610.zip
dependencies now work, although you cannot yet specify them for components
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@283 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/blink/event.rb16
-rw-r--r--lib/blink/transaction.rb8
-rw-r--r--test/other/tc_transactions.rb50
3 files changed, 67 insertions, 7 deletions
diff --git a/lib/blink/event.rb b/lib/blink/event.rb
index 1f3f21f72..99b922930 100644
--- a/lib/blink/event.rb
+++ b/lib/blink/event.rb
@@ -31,12 +31,15 @@ module Blink
# the transaction is passed in so that we can notify it if
# something fails
def trigger(transaction)
- # we need some mechanism for only triggering a subscription
- # once per transaction, but, um, we don't want it to only
- # be once per process lifetime
- # so, for now, just trigger as many times as we can, rather than
- # as few...
- unless @triggered
+ # this is potentially incomplete, because refreshing an object
+ # could theoretically kick off an event, which would not get run
+ # or, because we're executing the first subscription rather than
+ # the last, a later-refreshed object could somehow be connected
+ # to the "old" object rather than "new"
+ # but we're pretty far from that being a problem
+ if transaction.triggered(self) > 1
+ Blink.verbose "%s has already run" % self
+ else
Blink.verbose "'%s' generated '%s'; triggering '%s' on '%s'" %
[@source,@event,@method,@target]
begin
@@ -56,7 +59,6 @@ module Blink
#raise "We need to roll '%s' transaction back" %
#transaction
end
- #@triggered = true
end
end
end
diff --git a/lib/blink/transaction.rb b/lib/blink/transaction.rb
index f5252b436..7bf0c8557 100644
--- a/lib/blink/transaction.rb
+++ b/lib/blink/transaction.rb
@@ -87,6 +87,8 @@ class Transaction
@tree = tree
@toplevel = false
+ @triggered = Hash.new(0)
+
# of course, this won't work on the second run
unless defined? @@failures
@toplevel = true
@@ -132,6 +134,12 @@ class Transaction
}
end
#---------------------------------------------------------------
+
+ #---------------------------------------------------------------
+ def triggered(sub)
+ @triggered[sub] += 1
+ end
+ #---------------------------------------------------------------
end
end
#---------------------------------------------------------------
diff --git a/test/other/tc_transactions.rb b/test/other/tc_transactions.rb
index 48d0028b5..710ee5a16 100644
--- a/test/other/tc_transactions.rb
+++ b/test/other/tc_transactions.rb
@@ -138,4 +138,54 @@ class TestTransactions < Test::Unit::TestCase
transaction.evaluate
}
end
+
+ def test_both
+ transaction = nil
+ file = newfile()
+ service = newservice()
+ states = {}
+ check = [:group,:mode]
+ file[:check] = check
+
+ service[:running] = 1
+ service.sync
+
+ component = newcomp(file,service)
+
+ # 'requires' expects an array of arrays
+ service[:require] = [[file.class.name,file.name]]
+
+ assert_nothing_raised() {
+ file.retrieve
+ service.retrieve
+ }
+
+ check.each { |state|
+ states[state] = file[state]
+ }
+ assert_nothing_raised() {
+ file[:group] = @groups[1]
+ file[:mode] = "755"
+ }
+ assert_nothing_raised() {
+ transaction = component.evaluate
+ }
+
+ # this should cause a restart of the service
+ assert_nothing_raised() {
+ transaction.evaluate
+ }
+
+ # now set everything back to how it was
+ assert_nothing_raised() {
+ service[:running] = 0
+ service.sync
+ check.each { |state|
+ file[state] = states[state]
+ }
+ file.sync
+ }
+
+ end
+
end