unicorn.git  about / heads / tags
Rack HTTP server for Unix and fast clients
blob 77d670721aefcbf6047e9100a38426721cddba85 925 bytes (raw)
$ git show httpdate-nogvl:t/t0007-working_directory_no_embed_cli.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
 
#!/bin/sh
. ./test-lib.sh

t_plan 4 "config.ru inside alt working_directory (no embedded switches)"

t_begin "setup and start" && {
	unicorn_setup
	rm -rf $t_pfx.app
	mkdir $t_pfx.app

	cat > $t_pfx.app/config.ru <<EOF
use Rack::ContentLength
use Rack::ContentType, "text/plain"
run lambda { |env| [ 200, {}, [ "#{\$master_ppid}\\n" ] ] }
EOF
	# the whole point of this exercise
	echo "working_directory '$t_pfx.app'" >> $unicorn_config

	# allows ppid to be 1 in before_fork
	echo "preload_app true" >> $unicorn_config
	cat >> $unicorn_config <<\EOF
before_fork do |server,worker|
  $master_ppid = Process.ppid # should be zero to detect daemonization
end
EOF

	cd /
	unicorn -D -c $unicorn_config
	unicorn_wait_start
}

t_begin "hit with curl" && {
	body=$(curl -sSf http://$listen/)
}

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

t_begin "response body ppid == 1 (daemonized)" && {
	test "$body" -eq 1
}

t_done

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