fix: auth is per test, so in-memory is sufficient

This commit is contained in:
Aravinth Manivannan 2023-09-27 23:18:46 +05:30
parent 9d59085608
commit bd6afe2fd9
Signed by: realaravinth
GPG key ID: F8F50389936984FF
11 changed files with 20 additions and 226 deletions

View file

@ -1,16 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "\n UPDATE\n ftest_jobs\n SET\n job_state = (SELECT ID FROM ftest_job_states WHERE name = $1),\n scheduled_at = $2\n WHERE auth = $3;",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Text",
"Timestamptz",
"Text"
]
},
"nullable": []
},
"hash": "1a317e97df24ca0cd8e9e70e400757943787cc5698f1f78942150eea869abcc3"
}

View file

@ -1,17 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO ftest_jobs\n (commit_hash, job_state, auth, created_at)\n VALUES ($1, (SELECT ID FROM ftest_job_states WHERE name = $2), $3, $4)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Varchar",
"Text",
"Varchar",
"Timestamptz"
]
},
"nullable": []
},
"hash": "1b8b3e3dac6353829abcd3c49617542415b79ed6cbc2e7468e60b078dad5b53d"
}

View file

@ -1,52 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n ftest_jobs.ID,\n ftest_jobs.commit_hash,\n ftest_job_states.name,\n ftest_jobs.created_at,\n ftest_jobs.scheduled_at,\n ftest_jobs.finished_at\n\n FROM ftest_jobs\n INNER JOIN\n ftest_job_states\n ON\n ftest_job_states.ID = ftest_jobs.job_state\n WHERE\n ftest_job_states.name = $1;",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
},
{
"ordinal": 1,
"name": "commit_hash",
"type_info": "Varchar"
},
{
"ordinal": 2,
"name": "name",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "created_at",
"type_info": "Timestamptz"
},
{
"ordinal": 4,
"name": "scheduled_at",
"type_info": "Timestamptz"
},
{
"ordinal": 5,
"name": "finished_at",
"type_info": "Timestamptz"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
false,
false,
false,
false,
true,
true
]
},
"hash": "74bacf397f38e738e9d8dcc9ad5cc5c07915bff6276bd5005fd7221a76741e8b"
}

View file

@ -1,52 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n ftest_jobs.ID,\n ftest_jobs.commit_hash,\n ftest_job_states.name,\n ftest_jobs.created_at,\n ftest_jobs.scheduled_at,\n ftest_jobs.finished_at\n\n FROM ftest_jobs\n INNER JOIN\n ftest_job_states\n ON\n ftest_job_states.ID = ftest_jobs.job_state\n WHERE\n ftest_jobs.commit_hash = $1",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
},
{
"ordinal": 1,
"name": "commit_hash",
"type_info": "Varchar"
},
{
"ordinal": 2,
"name": "name",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "created_at",
"type_info": "Timestamptz"
},
{
"ordinal": 4,
"name": "scheduled_at",
"type_info": "Timestamptz"
},
{
"ordinal": 5,
"name": "finished_at",
"type_info": "Timestamptz"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
false,
false,
false,
false,
true,
true
]
},
"hash": "8f43686f9512d4e3f75e000515bdc90dd7c999a585e6b7b79459545bb583daa0"
}

View file

@ -1,16 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "\n UPDATE\n ftest_jobs\n SET\n job_state = (SELECT ID FROM ftest_job_states WHERE name = $1),\n finished_at = $2\n WHERE auth = $3;",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Text",
"Timestamptz",
"Text"
]
},
"nullable": []
},
"hash": "985c4f76d8ccef02d4c1c47628fa1360c49cf7d0f1eb4eeea73117cda7eefe91"
}

View file

@ -1,14 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO ftest_job_states\n (name) VALUES ($1) ON CONFLICT (name) DO NOTHING;",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Varchar"
]
},
"nullable": []
},
"hash": "c43b464586d8b356ef09ebff65649f86699411f7a0c1bc2db5ab6125cd5c2828"
}

View file

@ -1,14 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "\n DELETE FROM\n ftest_jobs\n WHERE commit_hash = $1;",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Text"
]
},
"nullable": []
},
"hash": "f41b0fa86f004be0f412517ae43aa8107433f6593077ee4197ff80cf2dc1f643"
}

View file

@ -1,22 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "SELECT EXISTS (SELECT 1 from ftest_job_states WHERE name = $1)",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "exists",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
null
]
},
"hash": "f93894995de10d5eb0dc6fd249fd93e22354dfe90d461c4a8e7469887cef63d6"
}

View file

@ -6,7 +6,6 @@ CREATE TABLE IF NOT EXISTS ftest_job_states (
CREATE TABLE IF NOT EXISTS ftest_jobs (
commit_hash VARCHAR(40) NOT NULL UNIQUE,
job_state INTEGER references ftest_job_states(ID) ON DELETE CASCADE,
auth VARCHAR(32) NOT NULL UNIQUE,
created_at timestamptz NOT NULL DEFAULT now(),
scheduled_at timestamptz DEFAULT NULL,
finished_at timestamptz DEFAULT NULL,

View file

@ -134,26 +134,24 @@ impl Database {
}
}
pub async fn add_job(&self, commit_hash: &str) -> ServiceResult<String> {
let auth = crate::utils::get_random(32);
pub async fn add_job(&self, commit_hash: &str) -> ServiceResult<()> {
let now = now_unix_time_stamp();
sqlx::query!(
"INSERT INTO ftest_jobs
(commit_hash, job_state, auth, created_at)
VALUES ($1, (SELECT ID FROM ftest_job_states WHERE name = $2), $3, $4)",
(commit_hash, job_state, created_at)
VALUES ($1, (SELECT ID FROM ftest_job_states WHERE name = $2), $3)",
commit_hash,
&JOB_STATE_CREATE.name,
&auth,
now
)
.execute(&self.pool)
.await
.map_err(map_register_err)?;
Ok(auth)
Ok(())
}
pub async fn mark_job_scheduled(&self, auth: &str) -> ServiceResult<()> {
pub async fn mark_job_scheduled(&self, commit_hash: &str) -> ServiceResult<()> {
let now = now_unix_time_stamp();
sqlx::query!(
"
@ -162,10 +160,10 @@ impl Database {
SET
job_state = (SELECT ID FROM ftest_job_states WHERE name = $1),
scheduled_at = $2
WHERE auth = $3;",
WHERE commit_hash = $3;",
&JOB_STATE_RUNNING.name,
now,
auth,
commit_hash,
)
.execute(&self.pool)
.await
@ -174,7 +172,7 @@ impl Database {
Ok(())
}
pub async fn mark_job_finished(&self, auth: &str) -> ServiceResult<()> {
pub async fn mark_job_finished(&self, commit_hash: &str) -> ServiceResult<()> {
let now = now_unix_time_stamp();
sqlx::query!(
"
@ -183,10 +181,10 @@ impl Database {
SET
job_state = (SELECT ID FROM ftest_job_states WHERE name = $1),
finished_at = $2
WHERE auth = $3;",
WHERE commit_hash = $3;",
&JOB_STATE_FINISH.name,
now,
auth,
commit_hash,
)
.execute(&self.pool)
.await
@ -272,7 +270,7 @@ impl Database {
let res = sqlx::query_as!(
SchedulerJob,
"SELECT
auth, commit_hash
commit_hash
FROM
ftest_jobs
WHERE
@ -319,7 +317,6 @@ pub fn map_row_not_found_err(e: sqlx::Error, row_not_found: ServiceError) -> Ser
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SchedulerJob {
pub commit_hash: String,
pub auth: String,
}
#[derive(Clone, Debug, PartialEq, Eq)]
@ -414,7 +411,7 @@ mod tests {
let _ = db.delete_job(COMMIT_HASH).await;
let _ = db.delete_job(COMMIT_HASH2).await;
let auth = db.add_job(COMMIT_HASH).await.unwrap();
db.add_job(COMMIT_HASH).await.unwrap();
let job = db.get_job(COMMIT_HASH).await.unwrap();
db.add_job(COMMIT_HASH2).await.unwrap();
let job2 = db.get_job(COMMIT_HASH2).await.unwrap();
@ -432,7 +429,7 @@ mod tests {
vec![job, job2.clone()]
);
db.mark_job_scheduled(&auth).await.unwrap();
db.mark_job_scheduled(COMMIT_HASH).await.unwrap();
let job = db.get_job(COMMIT_HASH).await.unwrap();
assert!(job.scheduled_at.is_some());
assert_eq!(
@ -440,7 +437,7 @@ mod tests {
vec![job]
);
db.mark_job_finished(&auth).await.unwrap();
db.mark_job_finished(COMMIT_HASH).await.unwrap();
let job = db.get_job(COMMIT_HASH).await.unwrap();
assert!(job.finished_at.is_some());
assert_eq!(

View file

@ -10,12 +10,14 @@ use url::Url;
use super::results::*;
use crate::complaince::result::Result as CResult;
use crate::complaince::suite::Suite;
use crate::utils::get_random;
pub struct SuiteRunnerState {
suite: Suite,
tests: HashMap<String, TestRunnerState>,
}
#[derive(Debug)]
pub struct TestRunnerState {
rx: Receiver<CResult>,
container_name: String,
@ -25,21 +27,21 @@ impl SuiteRunnerState {
pub async fn run(
container_host: &Url,
suite: &crate::complaince::suite::Suite,
auth: &str,
ctx: &crate::ctx::ArcCtx,
) -> ArchivableSuiteResult {
let state = Self::launch_suite(container_host, suite, auth, &ctx);
let state = Self::launch_suite(container_host, suite, &ctx);
state.collect_results(&ctx).await
}
fn launch_suite(
container_host: &Url,
suite: &crate::complaince::suite::Suite,
auth: &str,
ctx: &crate::ctx::ArcCtx,
) -> Self {
let mut tests = HashMap::with_capacity(suite.tests.len());
for test in suite.tests.iter() {
let auth = get_random(32);
println!("starting test {}", test.name);
let mut env = HashMap::new();
env.insert("FTEST_AUTH".into(), auth.to_owned());
env.insert(
@ -75,6 +77,7 @@ impl SuiteRunnerState {
},
);
}
println!("{:?}", tests);
SuiteRunnerState {
suite: suite.clone(),
tests,
@ -193,7 +196,6 @@ mod tests {
#[actix_rt::test]
async fn suite_runner_works() {
const LOGS: &str = "SUITE RUNNER LOG STRING";
const AUTH: &str = "asdfasdfasdfadsf";
let settings = Settings::new().unwrap();
let ctx = Ctx::new(settings.clone()).await;
@ -227,7 +229,6 @@ mod tests {
let state = SuiteRunnerState::launch_suite(
&Url::parse("http://suite_runner_works.service").unwrap(),
&suite,
AUTH,
&ctx,
);
assert_eq!(state.tests.len(), 2);