MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / test_github_20262

Function test_github_20262

src/environmentd/tests/server.rs:3337–3398  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3335#[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `epoll_wait` on OS `linux`
3336#[allow(clippy::disallowed_methods)]
3337fn test_github_20262() {
3338 let server = test_util::TestHarness::default().start_blocking();
3339 let mut client = server.connect(postgres::NoTls).unwrap();
3340 client.batch_execute("CREATE TABLE t (i INT);").unwrap();
3341
3342 let mut cancel = || {
3343 // Wait for the subscription to start.
3344 let conn_id = Retry::default()
3345 .retry(|_| {
3346 let conn_id: String = client
3347 .query_one(
3348 "SELECT s.connection_id::text FROM mz_internal.mz_subscriptions b JOIN mz_internal.mz_sessions s ON s.id = b.session_id",
3349 &[],
3350 )?
3351 .get(0);
3352 Ok::<_, postgres::Error>(conn_id)
3353 })
3354 .unwrap();
3355 client
3356 .query_one(&format!("SELECT pg_cancel_backend({conn_id})"), &[])
3357 .unwrap();
3358 };
3359
3360 let subscribe: serde_json::Value =
3361 serde_json::from_str(r#"{"queries":[{"query":"SUBSCRIBE t"}]}"#).unwrap();
3362 let subscribe = subscribe.to_string();
3363 let commit: serde_json::Value =
3364 serde_json::from_str(r#"{"queries":[{"query":"COMMIT"}]}"#).unwrap();
3365 let commit = commit.to_string();
3366 let select: serde_json::Value =
3367 serde_json::from_str(r#"{"queries":[{"query":"SELECT 1"}]}"#).unwrap();
3368 let select = select.to_string();
3369
3370 let (mut ws, _resp) = tungstenite::connect(server.ws_addr()).unwrap();
3371 test_util::auth_with_ws(&mut ws, BTreeMap::default()).unwrap();
3372 ws.send(Message::Text(subscribe.into())).unwrap();
3373 cancel();
3374 ws.send(Message::Text(commit.into())).unwrap();
3375 ws.send(Message::Text(select.into())).unwrap();
3376
3377 let mut expect = VecDeque::from([
3378 r#"{"type":"CommandStarting","payload":{"has_rows":true,"is_streaming":true}}"#.to_string(),
3379 r#"{"type":"Rows","payload":{"columns":[{"name":"mz_timestamp","type_oid":1700,"type_len":-1,"type_mod":2555908},{"name":"mz_diff","type_oid":20,"type_len":8,"type_mod":-1},{"name":"i","type_oid":23,"type_len":4,"type_mod":-1}]}}"#.to_string(),
3380 r#"{"type":"Error","payload":{"message":"canceling statement due to user request","code":"57014"}}"#.to_string(),
3381 r#"{"type":"ReadyForQuery","payload":"I"}"#.to_string(),
3382 r#"{"type":"Notice","payload":{"message":"there is no transaction in progress","code":"25P01","severity":"warning"}}"#.to_string(),
3383 r#"{"type":"CommandStarting","payload":{"has_rows":false,"is_streaming":false}}"#.to_string(),
3384 r#"{"type":"CommandComplete","payload":"COMMIT"}"#.to_string(),
3385 r#"{"type":"ReadyForQuery","payload":"I"}"#.to_string(),
3386 r#"{"type":"CommandStarting","payload":{"has_rows":true,"is_streaming":false}}"#.to_string(),
3387 format!(r#"{{"type":"Rows","payload":{{"columns":[{{"name":"{UNKNOWN_COLUMN_NAME}","type_oid":23,"type_len":4,"type_mod":-1}}]}}}}"#),
3388 r#"{"type":"Row","payload":["1"]}"#.to_string(),
3389 r#"{"type":"CommandComplete","payload":"SELECT 1"}"#.to_string(),
3390 r#"{"type":"ReadyForQuery","payload":"I"}"#.to_string(),
3391 ]);
3392 while !expect.is_empty() {
3393 if let Message::Text(text) = ws.read().unwrap() {
3394 let next = expect.pop_front().unwrap();

Callers

nothing calls this directly

Calls 15

auth_with_wsFunction · 0.85
TextClass · 0.85
start_blockingMethod · 0.80
unwrapMethod · 0.80
batch_executeMethod · 0.80
ws_addrMethod · 0.80
pop_frontMethod · 0.80
connectFunction · 0.50
connectMethod · 0.45
retryMethod · 0.45
getMethod · 0.45
query_oneMethod · 0.45

Tested by

no test coverage detected