-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat : added state update worker #36
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
pub mod proving; | ||
#[cfg(test)] | ||
pub mod snos; | ||
mod update_state; | ||
mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use crate::config::config_force_init; | ||
use crate::database::MockDatabase; | ||
use crate::jobs::types::{JobStatus, JobType}; | ||
use crate::queue::MockQueueProvider; | ||
use crate::tests::common::init_config; | ||
use crate::tests::workers::utils::{ | ||
db_create_job_expectations_update_state_worker, get_job_by_mock_id_vector, get_job_item_mock_by_id, | ||
}; | ||
use crate::workers::update_state::UpdateStateWorker; | ||
use crate::workers::Worker; | ||
use da_client_interface::MockDaClient; | ||
use httpmock::MockServer; | ||
use mockall::predicate::eq; | ||
use rstest::rstest; | ||
use std::error::Error; | ||
use uuid::Uuid; | ||
|
||
#[rstest] | ||
#[case(false, 0)] | ||
#[case(true, 5)] | ||
#[tokio::test] | ||
async fn test_update_state_worker( | ||
#[case] last_successful_job_exists: bool, | ||
#[case] number_of_processed_jobs: usize, | ||
) -> Result<(), Box<dyn Error>> { | ||
let server = MockServer::start(); | ||
let da_client = MockDaClient::new(); | ||
let mut db = MockDatabase::new(); | ||
let mut queue = MockQueueProvider::new(); | ||
|
||
const JOB_PROCESSING_QUEUE: &str = "madara_orchestrator_job_processing_queue"; | ||
|
||
// Mocking db function expectations | ||
// If no successful state update jobs exist | ||
if !last_successful_job_exists { | ||
db.expect_get_last_successful_job_by_type().with(eq(JobType::StateTransition)).times(1).returning(|_| Ok(None)); | ||
} else { | ||
// if successful state update job exists | ||
|
||
// mocking the return value of first function call (getting last successful jobs): | ||
db.expect_get_last_successful_job_by_type() | ||
.with(eq(JobType::StateTransition)) | ||
.times(1) | ||
.returning(|_| Ok(Some(get_job_item_mock_by_id("1".to_string(), Uuid::new_v4())))); | ||
|
||
// mocking the return values of second function call (getting completed proving worker jobs) | ||
db.expect_get_jobs_after_internal_id_by_job_type() | ||
.with(eq(JobType::ProofCreation), eq(JobStatus::Completed), eq("1".to_string())) | ||
.returning(move |_, _, _| { | ||
Ok(get_job_by_mock_id_vector( | ||
JobType::ProofCreation, | ||
JobStatus::Completed, | ||
number_of_processed_jobs as u64, | ||
2, | ||
)) | ||
}); | ||
|
||
// mocking getting of the jobs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's add a comment on where this check happens There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is pending? |
||
let completed_jobs = | ||
get_job_by_mock_id_vector(JobType::ProofCreation, JobStatus::Completed, number_of_processed_jobs as u64, 2); | ||
for job in completed_jobs { | ||
db.expect_get_job_by_internal_id_and_type() | ||
.times(1) | ||
.with(eq(job.internal_id.to_string()), eq(JobType::StateTransition)) | ||
.returning(|_, _| Ok(None)); | ||
} | ||
|
||
// mocking the creation of jobs | ||
db_create_job_expectations_update_state_worker( | ||
&mut db, | ||
get_job_by_mock_id_vector(JobType::ProofCreation, JobStatus::Completed, number_of_processed_jobs as u64, 2), | ||
); | ||
} | ||
|
||
// Queue function call simulations | ||
queue | ||
.expect_send_message_to_queue() | ||
.returning(|_, _, _| Ok(())) | ||
.withf(|queue, _payload, _delay| queue == JOB_PROCESSING_QUEUE); | ||
|
||
// mock block number (madara) : 5 | ||
let config = init_config( | ||
Some(format!("http://localhost:{}", server.port())), | ||
Some(db), | ||
Some(queue), | ||
Some(da_client), | ||
None, | ||
None, | ||
) | ||
.await; | ||
config_force_init(config).await; | ||
|
||
let update_state_worker = UpdateStateWorker {}; | ||
update_state_worker.run_worker().await?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should index collections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will create the issue for this.