unicorn.git  about / heads / tags
Rack HTTP server for Unix and fast clients
blob 6e56e30c43c5c67bcafd4ad77b03b7a36d64f523 1335 bytes (raw)
$ git show no-kgio-wip:t/t0009-winch_ttin.sh	# shows this blob on the CLI

 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
 
#!/bin/sh
. ./test-lib.sh
t_plan 8 "SIGTTIN succeeds after SIGWINCH"

t_begin "setup and start" && {
	unicorn_setup
cat >> $unicorn_config <<EOF
after_fork do |server, worker|
  # test script will block while reading from $fifo,
  File.open("$fifo", "wb") { |fp| fp.syswrite worker.nr.to_s }
end
EOF
	unicorn -D -c $unicorn_config pid.ru
	unicorn_wait_start
	test 0 -eq $(cat $fifo) || die "worker.nr != 0"
}

t_begin "read worker pid" && {
	orig_worker_pid=$(curl -sSf http://$listen/)
	test -n "$orig_worker_pid" && kill -0 $orig_worker_pid
}

t_begin "stop all workers" && {
	kill -WINCH $unicorn_pid
}

# we have to do this next step before delivering TTIN
# signals aren't guaranteed to delivered in order
t_begin "wait for worker to die" && {
	i=0
	while kill -0 $orig_worker_pid 2>/dev/null
	do
		i=$(( $i + 1 ))
		test $i -lt 600 || die "timed out"
		sleep 1
	done
}

t_begin "start one worker back up" && {
	kill -TTIN $unicorn_pid
}

t_begin "wait for new worker to start" && {
	test 0 -eq $(cat $fifo) || die "worker.nr != 0"
	new_worker_pid=$(curl -sSf http://$listen/)
	test -n "$new_worker_pid" && kill -0 $new_worker_pid
	test $orig_worker_pid -ne $new_worker_pid || \
	   die "worker wasn't replaced"
}

t_begin "killing succeeds" && {
	kill $unicorn_pid
}

t_begin "check stderr" && check_stderr

dbgcat r_err

t_done

git clone https://yhbt.net/unicorn.git