@@ -90,6 +90,85 @@ Y_UNIT_TEST_SUITE(KqpQueryService) {
90
90
WaitForZeroSessions (counters);
91
91
}
92
92
93
+ Y_UNIT_TEST (PeriodicTaskInSessionPool) {
94
+ auto kikimr = DefaultKikimrRunner ();
95
+ auto clientConfig = NGRpcProxy::TGRpcClientConfig (kikimr.GetEndpoint ());
96
+ NKqp::TKqpCounters counters (kikimr.GetTestServer ().GetRuntime ()->GetAppData ().Counters );
97
+
98
+ {
99
+ auto db = kikimr.GetQueryClient ();
100
+
101
+ TString id;
102
+ {
103
+ auto result = db.GetSession ().GetValueSync ();
104
+ UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), EStatus::SUCCESS, result.GetIssues ().ToString ());
105
+ UNIT_ASSERT (result.GetSession ().GetId ());
106
+ auto session = result.GetSession ();
107
+ id = session.GetId ();
108
+
109
+ auto execResult = session.ExecuteQuery (" SELECT 1;" ,
110
+ NYdb::NQuery::TTxControl::BeginTx ().CommitTx ()).ExtractValueSync ();
111
+ UNIT_ASSERT_VALUES_EQUAL (execResult.GetStatus (), EStatus::SUCCESS);
112
+ }
113
+ // This time is more then internal sdk periodic timeout but less than close session
114
+ // expect nothing happens with session in the pool
115
+ Sleep (TDuration::Seconds (10 ));
116
+
117
+ {
118
+ auto result = db.GetSession ().GetValueSync ();
119
+ UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), EStatus::SUCCESS, result.GetIssues ().ToString ());
120
+ UNIT_ASSERT (result.GetSession ().GetId () == id);
121
+
122
+ auto execResult = result.GetSession ().ExecuteQuery (" SELECT 1;" ,
123
+ NYdb::NQuery::TTxControl::BeginTx ().CommitTx ()).ExtractValueSync ();
124
+
125
+ UNIT_ASSERT_VALUES_EQUAL (execResult.GetStatus (), EStatus::SUCCESS);
126
+ }
127
+ }
128
+ WaitForZeroSessions (counters);
129
+ }
130
+
131
+ Y_UNIT_TEST (PeriodicTaskInSessionPoolSessionCloseByIdle) {
132
+ auto kikimr = DefaultKikimrRunner ();
133
+ auto clientConfig = NGRpcProxy::TGRpcClientConfig (kikimr.GetEndpoint ());
134
+ NKqp::TKqpCounters counters (kikimr.GetTestServer ().GetRuntime ()->GetAppData ().Counters );
135
+
136
+ {
137
+ auto settings = NYdb::NQuery::TClientSettings ().SessionPoolSettings (
138
+ NYdb::NQuery::TSessionPoolSettings ()
139
+ .MinPoolSize (0 )
140
+ .CloseIdleThreshold (TDuration::Seconds (1 )));
141
+ auto db = kikimr.GetQueryClient (settings);
142
+
143
+ TString id;
144
+ {
145
+ auto result = db.GetSession ().GetValueSync ();
146
+ UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), EStatus::SUCCESS, result.GetIssues ().ToString ());
147
+ UNIT_ASSERT (result.GetSession ().GetId ());
148
+ auto session = result.GetSession ();
149
+ id = session.GetId ();
150
+
151
+ auto execResult = session.ExecuteQuery (" SELECT 1;" ,
152
+ NYdb::NQuery::TTxControl::BeginTx ().CommitTx ()).ExtractValueSync ();
153
+ UNIT_ASSERT_VALUES_EQUAL (execResult.GetStatus (), EStatus::SUCCESS);
154
+ }
155
+
156
+ Sleep (TDuration::Seconds (11 ));
157
+ UNIT_ASSERT_VALUES_EQUAL (db.GetCurrentPoolSize (), 0 );
158
+
159
+ {
160
+ auto result = db.GetSession ().GetValueSync ();
161
+ UNIT_ASSERT_VALUES_EQUAL_C (result.GetStatus (), EStatus::SUCCESS, result.GetIssues ().ToString ());
162
+ UNIT_ASSERT (result.GetSession ().GetId () != id);
163
+
164
+ auto execResult = result.GetSession ().ExecuteQuery (" SELECT 1;" ,
165
+ NYdb::NQuery::TTxControl::BeginTx ().CommitTx ()).ExtractValueSync ();
166
+ UNIT_ASSERT_VALUES_EQUAL (execResult.GetStatus (), EStatus::SUCCESS);
167
+ }
168
+ }
169
+ WaitForZeroSessions (counters);
170
+ }
171
+
93
172
Y_UNIT_TEST (StreamExecuteQueryPure) {
94
173
auto kikimr = DefaultKikimrRunner ();
95
174
auto db = kikimr.GetQueryClient ();
0 commit comments