Skip to content
This repository has been archived by the owner on Jan 23, 2018. It is now read-only.

Commit

Permalink
refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Jul 23, 2008
1 parent d9d2952 commit 424d6bc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/conspire.rb
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/conspire/conspirator.rb
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions test/perf.rb
@@ -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'

Expand Down
4 changes: 2 additions & 2 deletions test/test_conspire.rb
Expand Up @@ -27,7 +27,6 @@ def setup
end

Conspire.start(:port => 7457, :path => LOCAL_SPACE)
Conspire.discover
end

def teardown
Expand All @@ -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
Expand Down

0 comments on commit 424d6bc

Please sign in to comment.