From 73072a32f6ccd8a28fcf533128d005bdf2c36bcb Mon Sep 17 00:00:00 2001
From: Konstantin Shulgin <konstantin.shulgin@gmail.com>
Date: Fri, 19 Aug 2011 16:54:21 +0400
Subject: [PATCH] feature 'master-valgrind':

Test enviroment:
  - start/stop server routine was updated.
Tests:
  - fix double start srvers.
---
 cfg/prscfg.c                            | 139 ++++++++++++------------
 test/box/sql.test                       |   2 -
 test/box_memcached/binary-get.test      |   1 -
 test/box_memcached/cas.test             |   1 -
 test/box_memcached/expirations.test     |   1 -
 test/box_memcached/flags.test           |   1 -
 test/box_memcached/flush-all.test       |   1 -
 test/box_memcached/getset.test          |   1 -
 test/box_memcached/incrdecr.test        |   1 -
 test/box_memcached/multiversioning.test |   1 -
 test/box_memcached/noreply.test         |   1 -
 test/lib/server.py                      |  33 +++++-
 12 files changed, 101 insertions(+), 82 deletions(-)

diff --git a/cfg/prscfg.c b/cfg/prscfg.c
index 53d0490fb9..6f930b537c 100644
--- a/cfg/prscfg.c
+++ b/cfg/prscfg.c
@@ -15,12 +15,13 @@ static prscfg_yyscan_t prscfgScannerInitBuffer(char *buffer, prscfg_yy_extra_typ
 static void prscfgScannerFinish(prscfg_yyscan_t scanner);
 static int prscfgGetLineNo(prscfg_yyscan_t yyscanner);
 
-/* A Bison parser, made by GNU Bison 2.4.3.  */
+
+/* A Bison parser, made by GNU Bison 2.4.1.  */
 
 /* Skeleton interface for Bison's Yacc-like parsers in C
    
-      Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-   2009, 2010 Free Software Foundation, Inc.
+      Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+   Free Software Foundation, Inc.
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -76,7 +77,7 @@ static int prscfgGetLineNo(prscfg_yyscan_t yyscanner);
 typedef union YYSTYPE
 {
 
-/* Line 1685 of yacc.c  */
+/* Line 1676 of yacc.c  */
 #line 89 "prscfg.y"
 
 	char		*str;
@@ -86,8 +87,8 @@ typedef union YYSTYPE
 
 
 
-/* Line 1685 of yacc.c  */
-#line 74 "y.tab.h"
+/* Line 1676 of yacc.c  */
+#line 75 "y.tab.h"
 } YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
@@ -97,12 +98,13 @@ typedef union YYSTYPE
 
 
 
-/* A Bison parser, made by GNU Bison 2.4.3.  */
+
+/* A Bison parser, made by GNU Bison 2.4.1.  */
 
 /* Skeleton implementation for Bison's Yacc-like parsers in C
    
-      Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-   2009, 2010 Free Software Foundation, Inc.
+      Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+   Free Software Foundation, Inc.
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -144,7 +146,7 @@ typedef union YYSTYPE
 #define YYBISON 1
 
 /* Bison version.  */
-#define YYBISON_VERSION "2.4.3"
+#define YYBISON_VERSION "2.4.1"
 
 /* Skeleton name.  */
 #define YYSKELETON_NAME "yacc.c"
@@ -256,7 +258,7 @@ static OptDef	*output;
 
 
 /* Line 189 of yacc.c  */
-#line 161 "y.tab.c"
+#line 162 "y.tab.c"
 
 /* Enabling traces.  */
 #ifndef YYDEBUG
@@ -315,7 +317,7 @@ typedef union YYSTYPE
 
 
 /* Line 214 of yacc.c  */
-#line 220 "y.tab.c"
+#line 221 "y.tab.c"
 } YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
@@ -327,7 +329,7 @@ typedef union YYSTYPE
 
 
 /* Line 264 of yacc.c  */
-#line 232 "y.tab.c"
+#line 233 "y.tab.c"
 
 #ifdef short
 # undef short
@@ -377,7 +379,7 @@ typedef short int yytype_int16;
 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
 
 #ifndef YY_
-# if defined YYENABLE_NLS && YYENABLE_NLS
+# if YYENABLE_NLS
 #  if ENABLE_NLS
 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
@@ -762,18 +764,9 @@ static const yytype_uint8 yystos[] =
 
 /* Like YYERROR except do call yyerror.  This remains here temporarily
    to ease the transition to the new meaning of YYERROR, for GCC.
-   Once GCC version 2 has supplanted version 1, this can go.  However,
-   YYFAIL appears to be in use.  Nevertheless, it is formally deprecated
-   in Bison 2.4.2's NEWS entry, where a plan to phase it out is
-   discussed.  */
+   Once GCC version 2 has supplanted version 1, this can go.  */
 
 #define YYFAIL		goto yyerrlab
-#if defined YYFAIL
-  /* This is here to suppress warnings from the GCC cpp's
-     -Wunused-macros.  Normally we don't worry about that warning, but
-     some users do, and we want to make it easy for users to remove
-     YYFAIL uses, which will produce warnings from Bison 2.5.  */
-#endif
 
 #define YYRECOVERING()  (!!yyerrstatus)
 
@@ -830,7 +823,7 @@ while (YYID (0))
    we won't break user code: when these are the locations we know.  */
 
 #ifndef YY_LOCATION_PRINT
-# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
+# if YYLTYPE_IS_TRIVIAL
 #  define YY_LOCATION_PRINT(File, Loc)			\
      fprintf (File, "%d.%d-%d.%d",			\
 	      (Loc).first_line, (Loc).first_column,	\
@@ -1574,35 +1567,35 @@ YYSTYPE yylval;
     {
         case 2:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 106 "prscfg.y"
     { output = (yyval.node) = (yyvsp[(1) - (1)].node); }
     break;
 
   case 3:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 110 "prscfg.y"
     { MakeAtom((yyval.atom), (yyvsp[(1) - (1)].str)); }
     break;
 
   case 4:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 111 "prscfg.y"
     { MakeAtom((yyval.atom), (yyvsp[(1) - (1)].str)); }
     break;
 
   case 5:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 115 "prscfg.y"
     { (yyval.atom) = (yyvsp[(1) - (1)].atom); }
     break;
 
   case 6:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 116 "prscfg.y"
     { 
 			(yyval.atom) = (yyvsp[(1) - (4)].atom); 
@@ -1614,21 +1607,21 @@ YYSTYPE yylval;
 
   case 7:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 125 "prscfg.y"
     { (yyval.atom) = (yyvsp[(1) - (1)].atom); }
     break;
 
   case 8:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 126 "prscfg.y"
     { MakeList((yyval.atom), (yyvsp[(1) - (3)].atom), (yyvsp[(3) - (3)].atom)); }
     break;
 
   case 9:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 130 "prscfg.y"
     { 
 			(yyval.atom) = (yyvsp[(1) - (4)].atom);
@@ -1640,140 +1633,140 @@ YYSTYPE yylval;
 
   case 10:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 136 "prscfg.y"
     { MakeList((yyval.atom), (yyvsp[(1) - (3)].atom), (yyvsp[(3) - (3)].atom)); }
     break;
 
   case 11:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 140 "prscfg.y"
     { (yyval.node) = (yyvsp[(1) - (1)].node); }
     break;
 
   case 12:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 141 "prscfg.y"
     { MakeList((yyval.node), (yyvsp[(3) - (3)].node), (yyvsp[(1) - (3)].node)); /* plainOptDef will revert the list */ }
     break;
 
   case 13:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 145 "prscfg.y"
     { SetSection((yyval.node), (yyvsp[(4) - (4)].node), (yyvsp[(2) - (4)].atom)); }
     break;
 
   case 14:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 146 "prscfg.y"
     { SetSection((yyval.node), (yyvsp[(4) - (4)].node), (yyvsp[(2) - (4)].atom)); }
     break;
 
   case 15:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 150 "prscfg.y"
     { (yyval.node) = (yyvsp[(1) - (1)].node); }
     break;
 
   case 16:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 151 "prscfg.y"
     { (yyval.node) = (yyvsp[(1) - (1)].node); }
     break;
 
   case 17:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 152 "prscfg.y"
     { MakeList((yyval.node), (yyvsp[(2) - (2)].node), (yyvsp[(1) - (2)].node)); }
     break;
 
   case 18:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 156 "prscfg.y"
     { MakeScalarParam((yyval.node), number, (yyvsp[(1) - (3)].atom), (yyvsp[(3) - (3)].str)); }
     break;
 
   case 19:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 157 "prscfg.y"
     { MakeScalarParam((yyval.node), string, (yyvsp[(1) - (3)].atom), (yyvsp[(3) - (3)].str)); }
     break;
 
   case 20:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 158 "prscfg.y"
     { MakeScalarParam((yyval.node), string, (yyvsp[(1) - (3)].atom), (yyvsp[(3) - (3)].str)); }
     break;
 
   case 21:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 159 "prscfg.y"
     { MakeScalarParam((yyval.node), string, (yyvsp[(1) - (3)].atom), (yyvsp[(3) - (3)].str)); }
     break;
 
   case 22:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 160 "prscfg.y"
     { MakeScalarParam((yyval.node), string, (yyvsp[(1) - (3)].atom), NULL); free((yyvsp[(3) - (3)].str)); }
     break;
 
   case 23:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 161 "prscfg.y"
     { MakeScalarParam((yyval.node), struct, (yyvsp[(1) - (6)].atom), (yyvsp[(4) - (6)].node)); SetParent( (yyval.node), (yyvsp[(4) - (6)].node) ); }
     break;
 
   case 24:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 162 "prscfg.y"
     { (yyvsp[(4) - (6)].node)->name = (yyvsp[(1) - (6)].atom); (yyval.node) = (yyvsp[(4) - (6)].node); }
     break;
 
   case 25:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 163 "prscfg.y"
     { MakeScalarParam((yyval.node), array, (yyvsp[(1) - (4)].atom), NULL); }
     break;
 
   case 26:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 164 "prscfg.y"
     { MakeScalarParam((yyval.node), struct, (yyvsp[(1) - (6)].atom), (yyvsp[(4) - (6)].node)); SetParent( (yyval.node), (yyvsp[(4) - (6)].node) ); }
     break;
 
   case 27:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 168 "prscfg.y"
     { (yyval.str)=NULL; }
     break;
 
   case 28:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 169 "prscfg.y"
     { (yyval.str)=NULL; }
     break;
 
   case 29:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 173 "prscfg.y"
     {
 			OptDef		*str;
@@ -1790,7 +1783,7 @@ YYSTYPE yylval;
 
   case 30:
 
-/* Line 1464 of yacc.c  */
+/* Line 1455 of yacc.c  */
 #line 184 "prscfg.y"
     {
 			OptDef		*str;
@@ -1808,8 +1801,8 @@ YYSTYPE yylval;
 
 
 
-/* Line 1464 of yacc.c  */
-#line 1714 "y.tab.c"
+/* Line 1455 of yacc.c  */
+#line 1706 "y.tab.c"
       default: break;
     }
   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -2020,7 +2013,7 @@ YYSTYPE yylval;
 
 
 
-/* Line 1684 of yacc.c  */
+/* Line 1675 of yacc.c  */
 #line 198 "prscfg.y"
 
 
@@ -2314,7 +2307,6 @@ typedef int flex_int32_t;
 typedef unsigned char flex_uint8_t; 
 typedef unsigned short int flex_uint16_t;
 typedef unsigned int flex_uint32_t;
-#endif /* ! C99 */
 
 /* Limits of integral types. */
 #ifndef INT8_MIN
@@ -2345,6 +2337,8 @@ typedef unsigned int flex_uint32_t;
 #define UINT32_MAX             (4294967295U)
 #endif
 
+#endif /* ! C99 */
+
 #endif /* ! FLEXINT_H */
 
 #ifdef __cplusplus
@@ -2418,7 +2412,15 @@ typedef void* yyscan_t;
 
 /* Size of default input buffer. */
 #ifndef YY_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k.
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
+ * Ditto for the __ia64__ case accordingly.
+ */
+#define YY_BUF_SIZE 32768
+#else
 #define YY_BUF_SIZE 16384
+#endif /* __ia64__ */
 #endif
 
 /* The state buf must be large enough to hold one state per character in the main buffer.
@@ -2759,7 +2761,7 @@ static YY_BUFFER_STATE buf = NULL;
 
 
 
-#line 503 "prscfg_scan.c"
+#line 512 "prscfg_scan.c"
 
 #define INITIAL 0
 #define xQUOTED 1
@@ -2853,10 +2855,6 @@ int prscfg_yyget_lineno (yyscan_t yyscanner );
 
 void prscfg_yyset_lineno (int line_number ,yyscan_t yyscanner );
 
-int prscfg_yyget_column  (yyscan_t yyscanner );
-
-void prscfg_yyset_column (int column_no ,yyscan_t yyscanner );
-
 YYSTYPE * prscfg_yyget_lval (yyscan_t yyscanner );
 
 void prscfg_yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
@@ -2893,7 +2891,12 @@ static int input (yyscan_t yyscanner );
 
 /* Amount of stuff to slurp up with each read. */
 #ifndef YY_READ_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k */
+#define YY_READ_BUF_SIZE 16384
+#else
 #define YY_READ_BUF_SIZE 8192
+#endif /* __ia64__ */
 #endif
 
 /* Copy whatever the last rule matched to the standard output. */
@@ -2912,7 +2915,7 @@ static int input (yyscan_t yyscanner );
 	if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
 		{ \
 		int c = '*'; \
-		unsigned n; \
+		size_t n; \
 		for ( n = 0; n < max_size && \
 			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
 			buf[n] = (char) c; \
@@ -3000,7 +3003,7 @@ YY_DECL
 #line 40 "prscfg.l"
 
 
-#line 744 "prscfg_scan.c"
+#line 754 "prscfg_scan.c"
 
     yylval = yylval_param;
 
@@ -3316,7 +3319,7 @@ YY_RULE_SETUP
 #line 182 "prscfg.l"
 YY_FATAL_ERROR( "flex scanner jammed" );
 	YY_BREAK
-#line 1060 "prscfg_scan.c"
+#line 1070 "prscfg_scan.c"
 
 	case YY_END_OF_BUFFER:
 		{
@@ -4045,8 +4048,8 @@ YY_BUFFER_STATE prscfg_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner
 
 /** Setup the input buffer state to scan the given bytes. The next call to prscfg_yylex() will
  * scan from a @e copy of @a bytes.
- * @param bytes the byte buffer to scan
- * @param len the number of bytes in the buffer pointed to by @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
  * @param yyscanner The scanner object.
  * @return the newly allocated buffer state object.
  */
diff --git a/test/box/sql.test b/test/box/sql.test
index 5189ca9d28..ad1d7960ef 100644
--- a/test/box/sql.test
+++ b/test/box/sql.test
@@ -61,7 +61,6 @@ print """
 # clean data and restart with appropriate config
 server.stop()
 server.deploy("box/tarantool_bug735140.cfg")
-server.start()
 
 exec sql "insert into t0 values ('Spears', 'Britney')"
 exec sql "select * from t0 where k0='Spears'"
@@ -74,7 +73,6 @@ exec sql "select * from t0 where k0='Spears'"
 # resore default suite config
 server.stop()
 server.deploy(self.suite_ini["config"])
-server.start()
 
 print """#
 # A test case for: http://bugs.launchpad.net/bugs/716683
diff --git a/test/box_memcached/binary-get.test b/test/box_memcached/binary-get.test
index c01141537b..c63eaaa72e 100644
--- a/test/box_memcached/binary-get.test
+++ b/test/box_memcached/binary-get.test
@@ -13,5 +13,4 @@ for i in range(len(blobs_list)):
 # resore default suite config
 server.stop()
 server.deploy(self.suite_ini["config"])
-server.start()
 # vim: syntax=python
diff --git a/test/box_memcached/cas.test b/test/box_memcached/cas.test
index 515414c3cc..843ca3da86 100644
--- a/test/box_memcached/cas.test
+++ b/test/box_memcached/cas.test
@@ -116,5 +116,4 @@ else:
 # resore default suite config
 server.stop()
 server.deploy(self.suite_ini["config"])
-server.start()
 # vim: syntax=python
diff --git a/test/box_memcached/expirations.test b/test/box_memcached/expirations.test
index 3ecd68f8c7..c941333f8f 100644
--- a/test/box_memcached/expirations.test
+++ b/test/box_memcached/expirations.test
@@ -63,5 +63,4 @@ exec memcached "add add 0 1 7\r\naddval2\r\n"
 # resore default suite config
 server.stop()
 server.deploy(self.suite_ini["config"])
-server.start()
 # vim: syntax=python
diff --git a/test/box_memcached/flags.test b/test/box_memcached/flags.test
index 348b4b81bf..320906cc2f 100644
--- a/test/box_memcached/flags.test
+++ b/test/box_memcached/flags.test
@@ -13,5 +13,4 @@ for flags in flags_list:
 # resore default suite config
 server.stop()
 server.deploy(self.suite_ini["config"])
-server.start()
 # vim: syntax=python
diff --git a/test/box_memcached/flush-all.test b/test/box_memcached/flush-all.test
index 11c3dc00ac..d7957749b7 100644
--- a/test/box_memcached/flush-all.test
+++ b/test/box_memcached/flush-all.test
@@ -25,5 +25,4 @@ exec memcached "get foo\r\n"
 # resore default suite config
 server.stop()
 server.deploy(self.suite_ini["config"])
-server.start()
 # vim: syntax=python
diff --git a/test/box_memcached/getset.test b/test/box_memcached/getset.test
index b277fb971c..1dc49936a2 100644
--- a/test/box_memcached/getset.test
+++ b/test/box_memcached/getset.test
@@ -64,5 +64,4 @@ while len < (1024 * 1028):
 # resore default suite config
 server.stop()
 server.deploy(self.suite_ini["config"])
-server.start()
 # vim: syntax=python
diff --git a/test/box_memcached/incrdecr.test b/test/box_memcached/incrdecr.test
index 8cd3568081..86e4f0124e 100644
--- a/test/box_memcached/incrdecr.test
+++ b/test/box_memcached/incrdecr.test
@@ -36,5 +36,4 @@ exec memcached "incr text 1\r\n"
 # resore default suite config
 server.stop()
 server.deploy(self.suite_ini["config"])
-server.start()
 # vim: syntax=python
diff --git a/test/box_memcached/multiversioning.test b/test/box_memcached/multiversioning.test
index 13a9cf08e0..77ebe779b2 100644
--- a/test/box_memcached/multiversioning.test
+++ b/test/box_memcached/multiversioning.test
@@ -33,7 +33,6 @@ else:
 # resore default suite config
 server.stop()
 server.deploy(self.suite_ini["config"])
-server.start()
 # check that we print clear memcached stats
 exec admin "show stat"
 # vim: syntax=python
diff --git a/test/box_memcached/noreply.test b/test/box_memcached/noreply.test
index 4c4e7ca3ff..d92750434e 100644
--- a/test/box_memcached/noreply.test
+++ b/test/box_memcached/noreply.test
@@ -40,5 +40,4 @@ exec memcached "get noreply:foo\r\n"
 # resore default suite config
 server.stop()
 server.deploy(self.suite_ini["config"])
-server.start()
 # vim: syntax=python
diff --git a/test/lib/server.py b/test/lib/server.py
index a56868f828..0887caa613 100644
--- a/test/lib/server.py
+++ b/test/lib/server.py
@@ -191,11 +191,13 @@ class Server(object):
             return
 
         self.process = pexpect.spawn(args[0], args[1:], cwd = self.vardir)
+
         # wait until the server is connected
         self.wait_until_started()
         # Set is_started flag, to nicely support cleanup during an exception.
         self.is_started = True
 
+
     def stop(self, silent=True):
         """Stop server instance. Do nothing if the server is not started,
         to properly shut down the server in case of an exception during
@@ -212,10 +214,17 @@ class Server(object):
             self.kill_old_server()
             return
 
+
         # kill process
-        self.process.kill(signal.SIGTERM)
-        self.process.expect(pexpect.EOF)
+        os.kill(self.read_pidfile(), signal.SIGTERM)
+        #self.process.kill(signal.SIGTERM)
+        if self.gdb:
+            self.process.expect(pexpect.EOF, timeout = 1 << 30)
+        else:
+            self.process.expect(pexpect.EOF)
         self.process.close()
+
+        self.wait_until_stoped()
         # clean-up processs flags
         self.is_started = False
         self.process = None
@@ -283,7 +292,7 @@ class Server(object):
     def wait_until_started(self):
         """Wait until the server is started and accepting connections"""
 
-        while (self.read_pidfile() != self.process.pid):
+        while self.read_pidfile() == -1:
             time.sleep(0.001)
 
         is_connected = False
@@ -296,3 +305,21 @@ class Server(object):
             except socket.error as e:
                 time.sleep(0.001)
 
+    def wait_until_stoped(self):
+        """Wait until the server is stoped and close sockets"""
+
+        while self.read_pidfile() != -1:
+            time.sleep(0.001)
+
+        is_connected = False
+        while not is_connected:
+            try:
+                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+                sock.connect(("localhost", self.port))
+                is_connected = True
+                sock.close()
+                time.sleep(0.001)
+                continue
+            except socket.error as e:
+                break
+
-- 
GitLab