~svn/ubuntu/oneiric/subversion/ppa

« back to all changes in this revision

Viewing changes to debian/patches/ruby-test-svnserve-race

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-12-13 17:57:16 UTC
  • mfrom: (1.1.6 upstream) (0.1.3 etch)
  • Revision ID: james.westby@ubuntu.com-20061213175716-2ysv6z4w5dpa2r2f
Tags: 1.4.2dfsg1-2ubuntu1
* Merge with Debian unstable; remaining changes:
  - Create pot file on build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh /usr/share/dpatch/dpatch-run
 
2
##
 
3
## ruby-test-svnserve-race by <peter@p12n.org>
 
4
##
 
5
## DP: Hack to try to avoid the race in the ruby testsuite harness between
 
6
## DP: starting up a svnserve process and trying to connect to it.  If the
 
7
## DP: client tries to connect too soon, before svnserve has initialised
 
8
## DP: itself, the test in progress gets a 'connection refused' and fails.
 
9
## DP:
 
10
## DP: This race causes random test failures on slow platforms - observed on
 
11
## DP: an arm with 32 MB of RAM, and m68k buildds of unknown specs.
 
12
 
 
13
@DPATCH@
 
14
Index: subversion/bindings/swig/ruby/test/util.rb
 
15
--- a/subversion/bindings/swig/ruby/test/util.rb
 
16
+++ b/subversion/bindings/swig/ruby/test/util.rb
 
17
@@ -1,4 +1,5 @@
 
18
 require "fileutils"
 
19
+require "socket"
 
20
 
 
21
 require "svn/client"
 
22
 require "svn/repos"
 
23
@@ -105,9 +106,7 @@
 
24
              "-d", "--foreground")
 
25
       }
 
26
       pid, status = Process.waitpid2(@svnserve_pid, Process::WNOHANG)
 
27
-      if status and status.exited?
 
28
-        STDERR.puts "port #{port} couldn't be used for svnserve"
 
29
-      else
 
30
+      if wait_until_svnserve_gets_available_at(port)
 
31
         @svnserve_port = port
 
32
         @repos_svnserve_uri =
 
33
           "svn://#{@svnserve_host}:#{@svnserve_port}#{@full_repos_path}"
 
34
@@ -221,4 +220,25 @@
 
35
     auth_baton[Svn::Core::AUTH_PARAM_CONFIG_DIR] = @config_path
 
36
     auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = @author
 
37
   end
 
38
+
 
39
+  # Waits until svnserve gets available at port +port+, avoiding the race
 
40
+  # condition between starting up a svnserve process and trying to connect
 
41
+  # to it (Bug#378837 in Debian's BTS).
 
42
+  def wait_until_svnserve_gets_available_at(port)
 
43
+    1000.times do |n|
 
44
+      begin
 
45
+       pid, status = Process.waitpid2(@svnserve_pid, Process::WNOHANG)
 
46
+       if status and status.exited?
 
47
+         STDERR.puts "port #{port} couldn't be used for svnserve"
 
48
+         return false
 
49
+       end
 
50
+       TCPSocket.new(@svnserve_host, port).close
 
51
+      rescue Errno::ECONNREFUSED
 
52
+       sleep(n < 10 ? 0.2 : 0.5)
 
53
+      else
 
54
+       return true
 
55
+      end
 
56
+    end
 
57
+    raise "svnserve couldn't get available at port #{port}"
 
58
+  end
 
59
 end