ASSERT_THROWS_CODE erronously report no exception was thrown

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Server Programmability
    • ALL
    • Hide

      Apply the attached code patch to r8.3.0-alpha3-429-g5a93344d6fb and run:

      bazel run +shard_role_test -- --filter=".*DroppedAndRecreated.*"
      
      Show
      Apply the attached code patch to r8.3.0-alpha3-429-g5a93344d6fb and run: bazel run +shard_role_test -- --filter= ".*DroppedAndRecreated.*"
    • Programmability 2026-02-02
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      ASSERT_THROWS_CODE test macro erroneously report no exception was thrown even if an exception was actually thrown by the given function. This is an example of the output of the unittest when this happens:

      src/mongo/db/shard_role/shard_role_test.cpp:2032: Failure
      Value of: [&] \{ (void)(restoreTransactionResourcesToOperationContext( operationContext(), std::move(yieldedTransactionResources))); }
      Expected: throws an exception which is a mongo::DBException which is an object whose given property is equal to ZoneNotFound
        Actual: 16-byte object <80-85 8C-FF 27-10 00-00 90-A1 54-C7 FF-FF 00-00>, does not throw any exception
      Stack trace:
        0xac2a1e786e9c: mongo::(anonymous namespace)::ShardRoleTest::testRestoreFailsIfCollectionDroppedAndRecreated()
        0xac2a1e7894a8: mongo::(anonymous namespace)::ShardRoleTest_RestoreForReadFailsIfCollectionDroppedAndRecreated_Test::TestBody()
        0xac2a287c8d68: testing::internal::HandleSehExceptionsInMethodIfSupported<>()
        0xac2a287b1714: testing::internal::HandleExceptionsInMethodIfSupported<>()
        0xac2a287930e8: testing::Test::Run()
        0xac2a28793bd0: testing::TestInfo::Run()
      ... Google Test internal frames ...
      

      In the output it says the code didn't throw but it actually threw QueryPlanKilled exception.

        1. SERVER-119017_repro.patch
          0.8 kB
          Tommaso Tocci

            Assignee:
            Alex Li
            Reporter:
            Tommaso Tocci
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: