File: ruby-tests.rake.disabled

package info (click to toggle)
ruby-redis 5.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,160 kB
  • sloc: ruby: 11,445; makefile: 117; sh: 24
file content (208 lines) | stat: -rw-r--r-- 5,800 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
require 'gem2deb/rake/testtask'

TMP                = "tmp"
BUILD_DIR          = File.join(TMP, "cache", "redis")
BINARY             = "/usr/bin/redis-server"
REDIS_CLIENT       = "/usr/bin/redis-cli"
REDIS_TRIB         = "/usr/share/doc/redis-tools/examples/redis-trib.rb"
PID_PATH           = File.join(TMP, "redis.pid")
SOCKET_PATH        = File.join(TMP, "redis.sock")
PORT               = 6381
SLAVE_PORT         = 6382
SLAVE_PID_PATH     = File.join(TMP, "redis_slave.pid")
SLAVE_SOCKET_PATH  = File.join(TMP, "redis_slave.sock")
SENTINEL_PORTS     = [ 6400, 6401, 6402 ]
SENTINEL_PID_PATHS = SENTINEL_PORTS.map { |port| File.join(TMP, "redis#{port}.pid") }
CLUSTER_PORTS      = [ 7000, 7001, 7002, 7003, 7004, 7005 ]
CLUSTER_PID_PATHS  = CLUSTER_PORTS.map { |port| File.join(TMP, "redis#{port}.pid") }
CLUSTER_CONF_PATHS = CLUSTER_PORTS.map { |port| File.join(TMP, "nodes#{port}.conf") }
CLUSTER_ADDRS      = CLUSTER_PORTS.map { |port| "127.0.0.1:#{port}" }

task :default => :all

desc "Run all the tests (start_all -> test_unit -> stop_all)"
task :all => [:start_all, :wait_ten_seconds, :test_units, :stop_all]

desc "Start all the Redis servers"
task :start_all => [:start, :start_slave, :start_sentinel, :start_cluster, :create_cluster]

desc "Stop all the Redis servers"
task :stop_all => [:stop_sentinel, :stop_slave, :stop, :stop_cluster]

task :create_tmp do
  FileUtils.mkdir_p(TMP)
end

def check_redis_running(pid_paths)
  pid_paths_arr = []

  if pid_paths.kind_of?(Array)
    pid_paths_arr.push(*pid_paths)
  else
    pid_paths_arr.push(pid_paths)
  end

  pid_paths_arr.each { |pid_path| 
    begin
      File.exist?("#{pid_path}") && Process.kill(0, File.read("#{pid_path}").to_i)
    rescue Errno::ESRCH
      FileUtils.rm "#{pid_path}"
      false
    end
  }
end

def kill_redis(pid_paths)
  pid_paths_arr = []

  if pid_paths.kind_of?(Array)
    pid_paths_arr.push(*pid_paths)
  else
    pid_paths_arr.push(pid_paths)
  end

  pid_paths_arr.each { |pid_path|
    begin
      File.exist?("#{pid_path}") && Process.kill("INT", File.read("#{pid_path}").to_i)
    rescue Errno::ESRCH
    end
    File.exist?("#{pid_path}") && FileUtils.rm("#{pid_path}")
  }
end

desc "Start the Redis server"
task :start => :create_tmp do
  unless check_redis_running(PID_PATH)
    abort "could not start redis-server"
  end

  unless system("#{BINARY}\
                    --daemonize  yes\
                    --pidfile    #{PID_PATH}\
                    --port       #{PORT}\
                    --unixsocket #{SOCKET_PATH}")
    abort "could not start redis-server"
  end
end

desc "Start the Redis server (slave)"
task :start_slave => :create_tmp do
  unless check_redis_running(SLAVE_PID_PATH)
    abort "could not start redis-server"
  end

  unless system("#{BINARY}\
                    --daemonize  yes\
                    --pidfile    #{SLAVE_PID_PATH}\
                    --port       #{SLAVE_PORT}\
                    --unixsocket #{SLAVE_SOCKET_PATH}\
                    --slaveof    127.0.0.1 #{PORT}")
    abort "could not start redis-server"
  end
end

desc "Start the Redis server (sentinel)"
task :start_sentinel => :create_tmp do
  unless check_redis_running(SENTINEL_PID_PATHS)
    abort "could not start redis-server"
  end

  SENTINEL_PORTS.each { |port|
    conf = "#{TMP}/sentinel#{port}.conf"

    File.open(conf, 'w') { |f| f.write (\
        "sentinel monitor                 master1 127.0.0.1 #{PORT} 2\n"\
        "sentinel down-after-milliseconds master1 5000\n"\
        "sentinel failover-timeout        master1 30000\n"\
        "sentinel parallel-syncs          master1 1\n")
      f.close
    }

    unless system("#{BINARY}\
                      #{conf}\
                      --daemonize  yes\
                      --pidfile    #{TMP}/redis#{port}.pid\
                      --port       #{port}\
                      --sentinel")
      abort "could not start redis-server"
    end
  }
end

desc "Start the Redis server (cluster)"
task :start_cluster => :create_tmp do
  unless check_redis_running(CLUSTER_PID_PATHS)
    abort "could not start redis-server"
  end

  CLUSTER_PORTS.each { |port|
    unless system("#{BINARY}\
                      --daemonize            yes\
                      --appendonly           yes\
                      --cluster-enabled      yes\
                      --cluster-config-file  #{TMP}/nodes#{port}.conf\
                      --cluster-node-timeout 5000\
                      --pidfile              #{TMP}/redis#{port}.pid\
                      --port                 #{port}\
                      --unixsocket           #{TMP}/redis#{port}.sock")
      abort "could not start redis-server"
    end
  }
end

desc "Stop the Redis server"
task :stop do
  kill_redis(PID_PATH)
end

desc "Stop the Redis server (slave)"
task :stop_slave do
  kill_redis(SLAVE_PID_PATH)
end

desc "Stop the Redis server (sentinel)"
task :stop_sentinel do
  kill_redis(SENTINEL_PID_PATHS)

  begin
    file = "#{TMP}/sentinel*.conf"
    Dir.glob(file) { |f| FileUtils.rm(f) }
  end

  true
end

desc "Stop the Redis server (cluster)"
task :stop_cluster do
  kill_redis(CLUSTER_PID_PATHS)

  begin
    file = "#{TMP}/appendonly.aof"
    File.exist?(file) && FileUtils.rm(file)
  end

  CLUSTER_CONF_PATHS.each { |path| File.exist?("#{path}") && FileUtils.rm("#{path}") }
  true
end

desc "Create the Redis cluster"
task :create_cluster do
  unless system("bin/cluster_creator " + CLUSTER_ADDRS.join(" "))
    abort "could not create redis cluster"
  end
end

task :clean do
end

task :wait_ten_seconds do
  sleep 10
end

Gem2Deb::Rake::TestTask.new(:test_units) do |t|
  ENV["SOCKET_PATH"] = SOCKET_PATH

  t.libs = %w(lib test)
  t.test_files = FileList["test/*_test.rb"] - FileList["test/ssl_test.rb"]
  t.options = '-v'
end