static void transactions_test_run_operation (json_test_ctx_t *ctx, const bson_t *test, const bson_t *operation, mongoc_collection_t *collection) { const char *description; const char *session_name; mongoc_client_session_t *session; if (bson_has_field (operation, "arguments.session")) { session_name = bson_lookup_utf8 (operation, "arguments.session"); if (!strcmp (session_name, "session0")) { session = ctx->sessions[0]; } else if (!strcmp (session_name, "session1")) { session = ctx->sessions[1]; } else { MONGOC_ERROR ("Unrecognized session name: %s", session_name); abort (); } } else { session = NULL; } description = bson_lookup_utf8 (test, "description"); /* we log warnings from abortTransaction. suppress warnings that we expect, * but don't suppress all: we want to know if any other tests log warnings */ if (!strcmp (description, "write conflict abort") || !strcmp (description, "abort ignores TransactionAborted") || !strcmp (description, "abort does not apply writeConcern")) { capture_logs (true); } /* json_test_operations() chose session0 or session1 from the * arguments.session field in the JSON test */ json_test_operation (test, operation, collection, session); capture_logs (false); }
static void test_write_concern_append (void) { mongoc_write_concern_t *wc; bson_t *cmd; cmd = tmp_bson ("{'foo': 1}"); capture_logs (true); /* cannot append invalid writeConcern */ wc = NULL; assert (!mongoc_write_concern_append (wc, cmd)); /* append valid writeConcern */ wc = mongoc_write_concern_new (); mongoc_write_concern_set_w (wc, 1); assert (mongoc_write_concern_append (wc, cmd)); ASSERT (match_bson (cmd, tmp_bson ("{'foo': 1, 'writeConcern': {'w': 1}}"), true)); mongoc_write_concern_destroy (wc); }
static int TestSuite_RunTest (TestSuite *suite, /* IN */ Test *test, /* IN */ int *count) /* INOUT */ { struct timespec ts1; struct timespec ts2; struct timespec ts3; char name[MAX_TEST_NAME_LENGTH]; char buf[MAX_TEST_NAME_LENGTH + 500]; int status = 0; snprintf (name, sizeof name, "%s%s", suite->name, test->name); name [sizeof name - 1] = '\0'; if (!test->check || test->check ()) { _Clock_GetMonotonic (&ts1); /* * TODO: If not verbose, close()/dup(/dev/null) for stdout. */ if (suite->flags & TEST_DEBUGOUTPUT) { _Print_StdOut ("Begin %s\n", name); } if ((suite->flags & TEST_NOFORK)) { #ifdef MONGOC_TRACE if (suite->flags & TEST_TRACE) { mongoc_log_set_handler (mongoc_log_default_handler, NULL); mongoc_log_trace_enable (); } else { mongoc_log_trace_disable (); } #endif srand (test->seed); test->func (test->ctx); status = 0; } else { status = TestSuite_RunFuncInChild (suite, test); } capture_logs (false); if (suite->silent) { return status; } _Clock_GetMonotonic (&ts2); _Clock_Subtract (&ts3, &ts2, &ts1); snprintf (buf, sizeof buf, " { \"status\": \"%s\", " "\"test_file\": \"%s\", " "\"seed\": \"%u\", " "\"start\": %u.%09u, " "\"end\": %u.%09u, " "\"elapsed\": %u.%09u }%s\n", (status == 0) ? "PASS" : "FAIL", name, test->seed, (unsigned)ts1.tv_sec, (unsigned)ts1.tv_nsec, (unsigned)ts2.tv_sec, (unsigned)ts2.tv_nsec, (unsigned)ts3.tv_sec, (unsigned)ts3.tv_nsec, ((*count) == 1) ? "" : ","); buf [sizeof buf - 1] = 0; _Print_StdOut ("%s", buf); if (suite->outfile) { fprintf (suite->outfile, "%s", buf); fflush (suite->outfile); } } else if (!suite->silent) { status = 0; snprintf (buf, sizeof buf, " { \"status\": \"SKIP\", \"test_file\": \"%s\" }%s\n", test->name, ((*count) == 1) ? "" : ","); buf [sizeof buf - 1] = '\0'; _Print_StdOut ("%s", buf); if (suite->outfile) { fprintf (suite->outfile, "%s", buf); fflush (suite->outfile); } } return status ? 1 : 0; }