chore: import upstream snapshot with attribution
CI / compile_and_lint (push) Failing after 0s
CI / docker_build (linux/amd64, -linux-amd64-duckdb, duckdb) (push) Failing after 0s
CI / docker_build (linux/arm64, -linux-arm64, minimal) (push) Failing after 2s
CI / docker_build (linux/arm64, -linux-arm64-duckdb, duckdb) (push) Failing after 1s
CI / docker_build (linux/amd64, minimal) (push) Failing after 1s
CI / test (, sqlite, sqlite::memory:) (push) Has been skipped
CI / test (mssql, mssql, mssql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (mysql, mysql, mysql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (oracle, oracle, Driver=Oracle 21 ODBC driver;Dbq=//127.0.0.1:1521/FREEPDB1;Uid=root;Pwd=Password123!) (push) Has been skipped
CI / test (postgres, odbc, Driver=PostgreSQL Unicode;Server=127.0.0.1;Port=5432;Database=sqlpage;UID=root;PWD=Password123!, true) (push) Has been skipped
CI / test (postgres, postgres, postgres://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / playwright (push) Has been skipped
CI / docker_build (linux/arm/v7, -linux-arm-v7, minimal) (push) Failing after 0s
CI / hurl_examples (push) Failing after 8s
deploy website / deploy_official_site (push) Failing after 1s
CI / hurl (${{ matrix.example }}) (push) Has been skipped
CI / docker_push (duckdb) (push) Has been cancelled
CI / docker_push (minimal) (push) Has been cancelled
CI / windows_test (push) Has been cancelled
CI / compile_and_lint (push) Failing after 0s
CI / docker_build (linux/amd64, -linux-amd64-duckdb, duckdb) (push) Failing after 0s
CI / docker_build (linux/arm64, -linux-arm64, minimal) (push) Failing after 2s
CI / docker_build (linux/arm64, -linux-arm64-duckdb, duckdb) (push) Failing after 1s
CI / docker_build (linux/amd64, minimal) (push) Failing after 1s
CI / test (, sqlite, sqlite::memory:) (push) Has been skipped
CI / test (mssql, mssql, mssql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (mysql, mysql, mysql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (oracle, oracle, Driver=Oracle 21 ODBC driver;Dbq=//127.0.0.1:1521/FREEPDB1;Uid=root;Pwd=Password123!) (push) Has been skipped
CI / test (postgres, odbc, Driver=PostgreSQL Unicode;Server=127.0.0.1;Port=5432;Database=sqlpage;UID=root;PWD=Password123!, true) (push) Has been skipped
CI / test (postgres, postgres, postgres://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / playwright (push) Has been skipped
CI / docker_build (linux/arm/v7, -linux-arm-v7, minimal) (push) Failing after 0s
CI / hurl_examples (push) Failing after 8s
deploy website / deploy_official_site (push) Failing after 1s
CI / hurl (${{ matrix.example }}) (push) Has been skipped
CI / docker_push (duckdb) (push) Has been cancelled
CI / docker_push (minimal) (push) Has been cancelled
CI / windows_test (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
use actix_web::http::StatusCode;
|
||||
use sqlpage::webserver::http::main_handler;
|
||||
|
||||
use crate::common::{get_request_to, make_app_data_from_config, test_config};
|
||||
|
||||
#[actix_web::test]
|
||||
async fn test_server_timing_disabled_in_production() -> actix_web::Result<()> {
|
||||
let mut config = test_config();
|
||||
config.environment = sqlpage::app_config::DevOrProd::Production;
|
||||
let app_data = make_app_data_from_config(config).await;
|
||||
|
||||
let req = crate::common::get_request_to_with_data(
|
||||
"/tests/sql_test_files/component_rendering/simple.sql",
|
||||
app_data,
|
||||
)
|
||||
.await?
|
||||
.to_srv_request();
|
||||
let resp = main_handler(req).await?;
|
||||
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
assert!(
|
||||
resp.headers().get("Server-Timing").is_none(),
|
||||
"Server-Timing header should not be present in production mode"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[actix_web::test]
|
||||
async fn test_server_timing_enabled_in_development() -> actix_web::Result<()> {
|
||||
let mut config = test_config();
|
||||
config.environment = sqlpage::app_config::DevOrProd::Development;
|
||||
let app_data = make_app_data_from_config(config).await;
|
||||
|
||||
let req = crate::common::get_request_to_with_data(
|
||||
"/tests/sql_test_files/data/postgres_cast_syntax.sql",
|
||||
app_data,
|
||||
)
|
||||
.await?
|
||||
.to_srv_request();
|
||||
let resp = main_handler(req).await?;
|
||||
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
let server_timing_header = resp
|
||||
.headers()
|
||||
.get("Server-Timing")
|
||||
.expect("Server-Timing header should be present in development mode");
|
||||
let header_value = server_timing_header.to_str().unwrap();
|
||||
|
||||
assert!(
|
||||
header_value.contains("sql_file;dur="),
|
||||
"Should contain sql_file timing: {header_value}"
|
||||
);
|
||||
assert!(
|
||||
header_value.contains("parse_req;dur="),
|
||||
"Should contain parse_req timing: {header_value}"
|
||||
);
|
||||
assert!(
|
||||
header_value.contains("bind_params;dur="),
|
||||
"Should contain bind_params timing: {header_value}"
|
||||
);
|
||||
assert!(
|
||||
header_value.contains("db_conn;dur="),
|
||||
"Should contain db_conn timing: {header_value}"
|
||||
);
|
||||
assert!(
|
||||
header_value.contains("row;dur="),
|
||||
"Should contain row timing: {header_value}"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[actix_web::test]
|
||||
async fn test_server_timing_format() -> actix_web::Result<()> {
|
||||
let req = get_request_to("/tests/sql_test_files/data/postgres_cast_syntax.sql")
|
||||
.await?
|
||||
.to_srv_request();
|
||||
let resp = main_handler(req).await?;
|
||||
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
let server_timing_header = resp.headers().get("Server-Timing").unwrap();
|
||||
let header_value = server_timing_header.to_str().unwrap();
|
||||
|
||||
let parts: Vec<&str> = header_value.split(", ").collect();
|
||||
assert!(parts.len() >= 5, "Should have at least 5 timing events");
|
||||
|
||||
for part in parts {
|
||||
assert!(
|
||||
part.contains(";dur="),
|
||||
"Each part should have name;dur= format: {part}"
|
||||
);
|
||||
let dur_parts: Vec<&str> = part.split(";dur=").collect();
|
||||
assert_eq!(dur_parts.len(), 2, "Should have name and duration: {part}");
|
||||
let duration: f64 = dur_parts[1]
|
||||
.parse()
|
||||
.expect("Duration should be a valid number");
|
||||
assert!(
|
||||
duration >= 0.0,
|
||||
"Duration should be non-negative: {duration}"
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[actix_web::test]
|
||||
async fn test_server_timing_in_redirect() -> actix_web::Result<()> {
|
||||
let mut config = test_config();
|
||||
config.environment = sqlpage::app_config::DevOrProd::Development;
|
||||
let app_data = make_app_data_from_config(config).await;
|
||||
|
||||
let req =
|
||||
crate::common::get_request_to_with_data("/tests/server_timing/redirect_test.sql", app_data)
|
||||
.await?
|
||||
.to_srv_request();
|
||||
let resp = main_handler(req).await?;
|
||||
|
||||
assert_eq!(
|
||||
resp.status(),
|
||||
StatusCode::FOUND,
|
||||
"Response should be a redirect"
|
||||
);
|
||||
let server_timing_header = resp
|
||||
.headers()
|
||||
.get("Server-Timing")
|
||||
.expect("Server-Timing header should be present in redirect responses");
|
||||
let header_value = server_timing_header.to_str().unwrap();
|
||||
|
||||
assert!(
|
||||
!header_value.is_empty(),
|
||||
"Server-Timing header should not be empty: {header_value}"
|
||||
);
|
||||
assert!(
|
||||
header_value.contains(";dur="),
|
||||
"Server-Timing header should contain timing events: {header_value}"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
select 'redirect' as component, '/destination.sql' as link;
|
||||
|
||||
Reference in New Issue
Block a user