|
1 | 1 | using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.Text.RegularExpressions; |
3 | 4 | using NUnit.Framework; |
4 | 5 | using Snowflake.Data.Client; |
@@ -280,6 +281,45 @@ public void TestConnectionCachePoolingDisabledForNewAuthenticators(string connec |
280 | 281 | Assert.IsFalse(isSessionReturnedToPool); |
281 | 282 | } |
282 | 283 |
|
| 284 | + [Test] |
| 285 | + public void TestShouldClearQueryContextCacheOnReturningToConnectionCache() |
| 286 | + { |
| 287 | + // arrange |
| 288 | + var session = CreateSessionWithCurrentStartTime("account=testAccount;user=testUser;password=testPassword"); |
| 289 | + var pool = SessionPool.CreateSessionCache(); |
| 290 | + var contextElement = new QueryContextElement(123, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), 1, "context"); |
| 291 | + var context = new ResponseQueryContext { Entries = new List<ResponseQueryContextElement> { new(contextElement) } }; |
| 292 | + session.UpdateQueryContextCache(context); |
| 293 | + Assert.AreEqual(1, session.GetQueryContextRequest().Entries.Count); |
| 294 | + |
| 295 | + // act |
| 296 | + var isSessionReturnedToPool = pool.AddSession(session, false); |
| 297 | + |
| 298 | + // assert |
| 299 | + Assert.IsTrue(isSessionReturnedToPool); |
| 300 | + Assert.AreEqual(0, session.GetQueryContextRequest().Entries.Count); |
| 301 | + } |
| 302 | + |
| 303 | + [Test] |
| 304 | + public void TestShouldClearQueryContextCacheOnReturningToConnectionPool() |
| 305 | + { |
| 306 | + // arrange |
| 307 | + var connectionString = "account=testAccount;user=testUser;password=testPassword"; |
| 308 | + var session = CreateSessionWithCurrentStartTime(connectionString); |
| 309 | + var pool = SessionPool.CreateSessionPool(connectionString, null, null, null); |
| 310 | + var contextElement = new QueryContextElement(123, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), 1, "context"); |
| 311 | + var context = new ResponseQueryContext { Entries = new List<ResponseQueryContextElement> { new(contextElement) } }; |
| 312 | + session.UpdateQueryContextCache(context); |
| 313 | + Assert.AreEqual(1, session.GetQueryContextRequest().Entries.Count); |
| 314 | + |
| 315 | + // act |
| 316 | + var isSessionReturnedToPool = pool.AddSession(session, false); |
| 317 | + |
| 318 | + // assert |
| 319 | + Assert.IsTrue(isSessionReturnedToPool); |
| 320 | + Assert.AreEqual(0, session.GetQueryContextRequest().Entries.Count); |
| 321 | + } |
| 322 | + |
283 | 323 | private SFSession CreateSessionWithCurrentStartTime(string connectionString) |
284 | 324 | { |
285 | 325 | var session = new SFSession(connectionString, new SessionPropertiesContext()); |
|
0 commit comments