use datafold::datafold_node::schema_client::SchemaServiceClient;
use datafold::schema::types::{JsonTopology, PrimitiveType, Schema, SchemaType, TopologyNode};
use std::collections::HashMap;
use std::time::Instant;
#[tokio::main]
async fn main() {
println!("\n๐งช Testing Schema Service Client Timeout Fix");
println!("==============================================\n");
let client = SchemaServiceClient::new("http://127.0.0.1:9999");
let mut schema = Schema::new(
"TestSchema".to_string(),
SchemaType::Single,
None,
Some(vec!["id".to_string(), "name".to_string()]),
None,
None,
);
schema.set_field_topology(
"id".to_string(),
JsonTopology::new(TopologyNode::Primitive {
value: PrimitiveType::String,
classifications: Some(vec!["word".to_string()]),
}),
);
schema.set_field_topology(
"name".to_string(),
JsonTopology::new(TopologyNode::Primitive {
value: PrimitiveType::String,
classifications: Some(vec!["word".to_string()]),
}),
);
schema.compute_schema_topology_hash();
println!("๐ก Attempting to connect to: http://127.0.0.1:9999/api/schemas");
println!(" (This service doesn't exist - testing timeout behavior)\n");
println!("โฑ๏ธ Expected: Timeout within 10-30 seconds");
println!("โ Before fix: Would hang forever\n");
let start = Instant::now();
match client.add_schema(&schema, HashMap::new()).await {
Ok(_) => {
println!("โ ERROR: Unexpected success!");
std::process::exit(1);
}
Err(e) => {
let elapsed = start.elapsed();
println!(
"โ
Request failed after {:.2} seconds",
elapsed.as_secs_f64()
);
println!("๐ Error message:\n {}\n", e);
if elapsed.as_secs() <= 35 {
println!("โ
SUCCESS: Timeout fix is working correctly!");
println!(
" โข Request timed out in {} seconds (expected: 10-30s)",
elapsed.as_secs()
);
println!(" โข Error message is clear and actionable");
println!(" โข No indefinite hanging occurred\n");
} else {
println!(
"โ ๏ธ WARNING: Timeout took {} seconds (expected <35s)",
elapsed.as_secs()
);
println!(
" This is longer than expected but still better than hanging forever.\n"
);
}
}
}
println!("๐ฏ Test complete!");
}