~vlad-lesin/percona-server/mysql-5.0.33-original

« back to all changes in this revision

Viewing changes to mysql-test/t/wait_for_socket.sh

  • Committer: Vlad Lesin
  • Date: 2012-07-31 09:21:34 UTC
  • Revision ID: vladislav.lesin@percona.com-20120731092134-zfodx022b7992wsi
VirginĀ 5.0.33

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
###########################################################################
 
4
 
 
5
# NOTE: this script returns 0 (success) even in case of failure (except for
 
6
# usage-error). This is because this script is executed under
 
7
# mysql-test-run[.pl] and it's better to examine particular problem in log
 
8
# file, than just having said that the test case has failed.
 
9
 
 
10
###########################################################################
 
11
 
 
12
basename=`basename "$0"`
 
13
dirname=`dirname "$0"`
 
14
 
 
15
###########################################################################
 
16
 
 
17
. "$dirname/utils.sh"
 
18
 
 
19
###########################################################################
 
20
 
 
21
if [ $# -ne 7 ]; then
 
22
  echo "Usage: wait_for_socket.sh <executable path> <socket path> <username> <password> <db> <timeout> <test id>"
 
23
  exit 1
 
24
fi
 
25
 
 
26
client_exe="$1"
 
27
socket_path="$2"
 
28
username="$3"
 
29
password="$4"
 
30
db="$5"
 
31
total_timeout="$6"
 
32
test_id="$7"
 
33
log_file="$MYSQLTEST_VARDIR/log/$test_id.log"
 
34
 
 
35
log_debug "-- $basename: starting --"
 
36
log_debug "client_exe: '$client_exe'"
 
37
log_debug "socket_path: '$socket_path'"
 
38
log_debug "username: '$username'"
 
39
log_debug "password: '$password'"
 
40
log_debug "db: '$db'"
 
41
log_debug "total_timeout: '$total_timeout'"
 
42
log_debug "test_id: '$test_id'"
 
43
log_debug "log_file: '$log_file'"
 
44
 
 
45
###########################################################################
 
46
 
 
47
if [ -z "$client_exe" ]; then
 
48
  log_error "Invalid path to client executable ($client_exe)."
 
49
  quit 0;
 
50
fi
 
51
 
 
52
if [ ! -x "$client_exe" ]; then
 
53
  log_error "Client by path '$client_exe' is not available."
 
54
  quit 0;
 
55
fi
 
56
 
 
57
if [ -z "$socket_path" ]; then
 
58
  log_error "Invalid socket patch ($socket_path)."
 
59
  quit 0
 
60
fi
 
61
 
 
62
###########################################################################
 
63
 
 
64
client_args="--silent --socket=$socket_path --connect_timeout=1 "
 
65
 
 
66
[ -n "$username" ] && client_args="$client_args --user=$username "
 
67
[ -n "$password" ] && client_args="$client_args --password=$password "
 
68
[ -n "$db" ] && client_args="$client_args $db"
 
69
 
 
70
log_debug "client_args: '$client_args'"
 
71
 
 
72
###########################################################################
 
73
 
 
74
cur_attempt=1
 
75
 
 
76
while true; do
 
77
 
 
78
  log_debug "cur_attempt: $cur_attempt."
 
79
 
 
80
  if ( echo 'quit' | "$client_exe" $client_args >/dev/null 2>&1 ); then
 
81
    log_info "Success: server is ready to accept connection on socket."
 
82
    quit 0
 
83
  fi
 
84
 
 
85
  [ $cur_attempt -ge $total_timeout ] && break
 
86
 
 
87
  sleep 1
 
88
 
 
89
  cur_attempt=`expr $cur_attempt + 1`
 
90
 
 
91
done
 
92
 
 
93
log_error "Server does not accept connections after $total_timeout seconds."
 
94
quit 0