|
11 | 11 |
|
12 | 12 | USERVER_NAMESPACE_BEGIN |
13 | 13 |
|
| 14 | +#if 0 |
| 15 | + |
14 | 16 | namespace bson = formats::bson; |
15 | 17 |
|
16 | 18 | // NOLINTNEXTLINE(google-build-using-namespace) |
@@ -273,4 +275,47 @@ UTEST_F(MongoTransaction, ParallelTrancactions) { |
273 | 275 | EXPECT_THAT(found_docs, ::testing::ElementsAre(bson::MakeDoc("name", "test_user", "age", 30))); |
274 | 276 | } |
275 | 277 |
|
| 278 | +UTEST_F(MongoTransaction, InvalidSessionIdReproducer) { |
| 279 | + static const std::string kCollectionName = "test_invalid_session_id"; |
| 280 | + |
| 281 | + auto config = MakeTestPoolConfig(); |
| 282 | + config.pool_settings.initial_size = 1; |
| 283 | + config.pool_settings.max_size = 3; |
| 284 | + config.pool_settings.idle_limit = 2; |
| 285 | + |
| 286 | + auto pool = MakePool("userver_mongotest_invalid_session_id", config); |
| 287 | + |
| 288 | + auto coll = pool.GetCollection(kCollectionName); |
| 289 | + |
| 290 | + { |
| 291 | + std::vector<formats::bson::Document> docs; |
| 292 | + docs.reserve(10); |
| 293 | + for (int i = 0; i < 10; ++i) { |
| 294 | + docs.push_back(bson::MakeDoc("foo", "bar", "value", i)); |
| 295 | + } |
| 296 | + coll.InsertMany(std::move(docs)); |
| 297 | + } |
| 298 | + |
| 299 | + using formats::bson::MakeDoc; |
| 300 | + |
| 301 | + auto txn = pool.BeginTransaction(); |
| 302 | + // GetCollection starts a transaction using client_1 from the pool |
| 303 | + auto coll_txn = txn.GetCollection(kCollectionName); |
| 304 | + |
| 305 | + // Find uses the same client_1 from the pool because initial_size == 1 |
| 306 | + // and returns a Cursor that holds this client |
| 307 | + // |
| 308 | + // TODO: transaction is not usable after that??? |
| 309 | + auto cursor = coll.Find(MakeDoc("foo", "bar")); |
| 310 | + |
| 311 | + // TODO: Must be fatal or must not compile: two cursors in the same transaction? |
| 312 | + auto cursor = coll.Find(MakeDoc("foo", "bar")); |
| 313 | + |
| 314 | + // TODO: Must be fatal or must not compile: executing not in a transaction |
| 315 | + UASSERT_THROW( coll_txn.InsertOne(MakeDoc("foo", "bar", "value", 11)) ); |
| 316 | + txn.Commit(); |
| 317 | +} |
| 318 | + |
| 319 | +#endif |
| 320 | + |
276 | 321 | USERVER_NAMESPACE_END |
0 commit comments