Permalink
Browse files

refactor tests

  • Loading branch information...
1 parent d9d2952 commit 424d6bc2aafe2503f5026a1aa171d9382635e3c0 @technomancy committed Jul 23, 2008
Showing with 8 additions and 5 deletions.
  1. +2 −2 lib/conspire.rb
  2. +1 −1 lib/conspire/conspirator.rb
  3. +3 −0 test/perf.rb
  4. +2 −2 test/test_conspire.rb
View
@@ -24,7 +24,7 @@ def start(options = {})
@options = DEFAULT_OPTIONS.merge(options)
FileUtils.mkdir_p(@options[:path]) unless File.exist? @options[:path]
- `cd #{@options[:path]}; git init` unless File.exist? @options[:path] + '/.git'
+ `cd #{@options[:path]}; git init` if ! File.exist? @options[:path] + '/.git'
@repo = Grit::Repo.new(@options[:path])
@thread = Thread.new do
@@ -36,7 +36,7 @@ def start(options = {})
# This should be called periodically
def discover(wait = DISCOVER_TIME)
Gitjour::Application.discover('_git._tcp', wait) do |service|
- next if service.name !~ /-#{SERVICE_NAME}/
+ next if service.name !~ Regexp.new(SERVICE_NAME)
next if service.port.to_i == @options[:port].to_i # TODO: and local
# No-op if we've got it already, since @conspirators is a Set
@conspirators << Conspirator.new(service.host, service.port, service.name)
@@ -2,7 +2,7 @@ module Conspire
class Conspirator
attr_accessor :last_synced, :host, :port, :name
- def initialize(host, port, name)
+ def initialize(host, port, name = SERVICE_NAME)
@host, @port, @name = host, port || DEFAULT_OPTIONS[:port], name
end
View
@@ -1,5 +1,8 @@
#!/usr/bin/env ruby
+# Just a total ad-hoc test to make sure this whole concept is even feasible.
+# On my 1.6 Core 2 Duo laptop I get 38 commits in 10s
+
require 'fileutils'
require 'timeout'
View
@@ -27,7 +27,6 @@ def setup
end
Conspire.start(:port => 7457, :path => LOCAL_SPACE)
- Conspire.discover
end
def teardown
@@ -39,11 +38,12 @@ def teardown
end
def test_discover
+ Conspire.discover
assert_equal [7458], Conspire.conspirators.map{ |c| c.port }
end
def test_sync
- assert File.exist?("#{LOCAL_SPACE}/.git")
+ Conspire.conspirators << Conspire::Conspirator.new('dynabook', '7458')
Conspire.sync_all
assert_equal ["#{LOCAL_SPACE}/file"], Dir.glob("#{LOCAL_SPACE}/*")
end

0 comments on commit 424d6bc

Please sign in to comment.