Browse Source

Add massive test for sqlite.

Brian Aker 12 years ago
parent
commit
3f46fd6cb4
5 changed files with 71 additions and 13 deletions
  1. 10 1
      libtest/client.cc
  2. 1 0
      libtest/client.hpp
  3. 3 3
      libtest/server.cc
  4. 6 0
      libtest/server.h
  5. 51 9
      tests/sqlite_test.cc

+ 10 - 1
libtest/client.cc

@@ -46,6 +46,7 @@
 namespace libtest {
 
 SimpleClient::SimpleClient(const std::string& hostname_, in_port_t port_) :
+  _is_connected(false),
   _hostname(hostname_),
   _port(port_),
   sock_fd(INVALID_SOCKET),
@@ -60,7 +61,13 @@ bool SimpleClient::ready(int event_)
   fds[0].events= event_;
   fds[0].revents= 0;
 
-  int ready_fds= poll(fds, 1, 5000);
+  int timeout= 5000;
+  if (_is_connected == false)
+  {
+    timeout= timeout * 30;
+  }
+
+  int ready_fds= poll(fds, 1, timeout);
 
   if (ready_fds == -1)
   {
@@ -90,6 +97,7 @@ bool SimpleClient::ready(int event_)
       return false;
     }
 
+    _is_connected= true;
     if (fds[0].revents & event_)
     {
       return true;
@@ -148,6 +156,7 @@ void SimpleClient::close_socket()
 
 bool SimpleClient::instance_connect()
 {
+  _is_connected= false;
   struct addrinfo *ai;
   if ((ai= lookup()))
   {

+ 1 - 0
libtest/client.hpp

@@ -69,6 +69,7 @@ private: // Methods
   bool ready(int event_);
 
 private:
+  bool _is_connected;
   std::string _hostname;
   in_port_t _port;
   int sock_fd;

+ 3 - 3
libtest/server.cc

@@ -117,7 +117,8 @@ Server::Server(const std::string& host_arg, const in_port_t port_arg,
   _port(port_arg),
   _hostname(host_arg),
   _app(executable, _is_libtool),
-  out_of_ban_killed_(false)
+  out_of_ban_killed_(false),
+  _timeout(40)
 {
 }
 
@@ -271,7 +272,6 @@ bool Server::start()
   bool pinged= false;
   uint32_t this_wait= 0;
   {
-    uint32_t timeout= 40; // This number should be high enough for valgrind startup (which is slow)
     uint32_t waited;
     uint32_t retry;
 
@@ -286,7 +286,7 @@ bool Server::start()
       {
         break;
       }
-      else if (waited >= timeout)
+      else if (waited >= _timeout)
       {
         break;
       }

+ 6 - 0
libtest/server.h

@@ -265,6 +265,11 @@ public:
     return out_of_ban_killed_;
   }
 
+  void timeout(uint32_t timeout_)
+  {
+    _timeout= timeout_;
+  }
+
 protected:
   bool set_pid_file();
   Options _options;
@@ -281,6 +286,7 @@ private:
   bool args(Application&);
 
   std::string _error;
+  uint32_t _timeout; // This number should be high enough for valgrind startup (which is slow)
 };
 
 std::ostream& operator<<(std::ostream& output, const libtest::Server &arg);

+ 51 - 9
tests/sqlite_test.cc

@@ -244,10 +244,8 @@ static test_return_t collection_cleanup(void *object)
 }
 
 
-static test_return_t lp_1054377_TEST(void *object)
+static test_return_t queue_restart_TEST(Context *test, const int32_t inserted_jobs, uint32_t timeout)
 {
-  Context *test= (Context *)object;
-  test_truth(test);
   server_startup_st &servers= test->_servers;
 
   std::string sql_file= libtest::create_tmpfile("sqlite");
@@ -261,7 +259,6 @@ static test_return_t lp_1054377_TEST(void *object)
     sql_buffer,
     0 };
 
-  const int32_t inserted_jobs= 8;
   {
     in_port_t first_port= libtest::get_free_port();
 
@@ -279,11 +276,33 @@ static test_return_t lp_1054377_TEST(void *object)
       gearman_job_handle_t job_handle;
       for (int32_t x= 0; x < inserted_jobs; ++x)
       {
-        test_compare(gearman_client_do_background(&client,
-                                                  __func__, // func
-                                                  NULL, // unique
-                                                  test_literal_param("foo"),
-                                                  job_handle), GEARMAN_SUCCESS);
+        switch (random() % 3)
+        {
+        case 0:
+          test_compare(gearman_client_do_background(&client,
+                                                    __func__, // func
+                                                    NULL, // unique
+                                                    test_literal_param("foo"),
+                                                    job_handle), GEARMAN_SUCCESS);
+          break;
+
+        case 1:
+          test_compare(gearman_client_do_low_background(&client,
+                                                        __func__, // func
+                                                        NULL, // unique
+                                                        test_literal_param("fudge"),
+                                                        job_handle), GEARMAN_SUCCESS);
+          break;
+
+        default:
+        case 2:
+          test_compare(gearman_client_do_high_background(&client,
+                                                         __func__, // func
+                                                         NULL, // unique
+                                                         test_literal_param("history"),
+                                                         job_handle), GEARMAN_SUCCESS);
+          break;
+        }
       }
     }
 
@@ -314,6 +333,11 @@ static test_return_t lp_1054377_TEST(void *object)
 
     test_true(server_startup(servers, "gearmand", first_port, 2, argv));
 
+    if (timeout)
+    {
+      servers.last()->timeout(timeout);
+    }
+
     {
       Worker worker(first_port);
       Called called;
@@ -375,6 +399,23 @@ static test_return_t lp_1054377_TEST(void *object)
   return TEST_SUCCESS;
 }
 
+static test_return_t lp_1054377_TEST(void* object)
+{
+  Context *test= (Context *)object;
+  test_truth(test);
+
+  return queue_restart_TEST(test, 8, 0);
+}
+
+static test_return_t lp_1054377x20K_TEST(void* object)
+{
+  test_skip(true, libtest::is_massive());
+
+  Context *test= (Context *)object;
+  test_truth(test);
+
+  return queue_restart_TEST(test, 20000, 200);
+}
 
 static void *world_create(server_startup_st& servers, test_return_t& error)
 {
@@ -419,6 +460,7 @@ test_st regressions[] ={
 
 test_st queue_restart_TESTS[] ={
   {"lp:1054377", 0, lp_1054377_TEST },
+  {"lp:1054377 x 20000", 0, lp_1054377x20K_TEST },
   {0, 0, 0}
 };