Example #1
0
/** This is the testing function for the ssl-test lib
 *
 * The basic idea is that you spin up a client and server, which will
 * communicate over a mongoc-stream-tls, with varying mongoc_ssl_opt's.  The
 * client and server speak a simple echo protocol, so all we're really testing
 * here is that any given configuration succeeds or fails as it should
 */
void
ssl_test (mongoc_ssl_opt_t *client,
          mongoc_ssl_opt_t *server,
          const char *host,
          ssl_test_result_t *client_result,
          ssl_test_result_t *server_result)
{
   ssl_test_data_t data = {0};
   bson_thread_t threads[2];
   int i, r;

   data.server = server;
   data.client = client;
   data.client_result = client_result;
   data.server_result = server_result;
   data.host = host;

   bson_mutex_init (&data.cond_mutex);
   mongoc_cond_init (&data.cond);

   r = bson_thread_create (threads, &ssl_test_server, &data);
   BSON_ASSERT (r == 0);

   r = bson_thread_create (threads + 1, &ssl_test_client, &data);
   BSON_ASSERT (r == 0);

   for (i = 0; i < 2; i++) {
      r = bson_thread_join (threads[i]);
      BSON_ASSERT (r == 0);
   }

   bson_mutex_destroy (&data.cond_mutex);
   mongoc_cond_destroy (&data.cond);
}
Example #2
0
static void
test_bson_oid_init_with_threads (void)
{
   bson_context_t *context;
   int i;

   {
      bson_context_flags_t flags = 0;
      bson_context_t *contexts[N_THREADS];
      bson_thread_t threads[N_THREADS];

#if defined(__linux__)
      flags |= BSON_CONTEXT_USE_TASK_ID;
#endif

      for (i = 0; i < N_THREADS; i++) {
         contexts[i] = bson_context_new(flags);
         bson_thread_create(&threads[i], NULL, oid_worker, contexts[i]);
      }

      for (i = 0; i < N_THREADS; i++) {
         bson_thread_join(threads[i], NULL);
      }

      for (i = 0; i < N_THREADS; i++) {
         bson_context_destroy(contexts[i]);
      }
   }

   /*
    * Test threaded generation of oids using a single context;
    */
   {
      bson_thread_t threads[N_THREADS];

      context = bson_context_new(BSON_CONTEXT_THREAD_SAFE);

      for (i = 0; i < N_THREADS; i++) {
         bson_thread_create(&threads[i], NULL, oid_worker, context);
      }

      for (i = 0; i < N_THREADS; i++) {
         bson_thread_join(threads[i], NULL);
      }

      bson_context_destroy(context);
   }
}