Skip to content

Commit db80cab

Browse files
committed
Use #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
1 parent e8935fe commit db80cab

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

magicblock-committor-service/src/tasks/mod.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@ use magicblock_program::magic_scheduled_base_intent::{
1919
};
2020
use solana_account::{Account, ReadableAccount};
2121
use solana_pubkey::Pubkey;
22-
use solana_rpc_client::rpc_client::RpcClient;
23-
use solana_sdk::{
24-
commitment_config::CommitmentConfig, instruction::Instruction,
25-
};
22+
use solana_sdk::instruction::Instruction;
2623
use thiserror::Error;
2724

28-
use crate::{
29-
config::ChainConfig, tasks::visitor::Visitor, ComputeBudgetConfig,
30-
};
25+
use crate::tasks::visitor::Visitor;
3126

3227
pub mod args_task;
3328
pub mod buffer_task;
@@ -114,7 +109,7 @@ pub struct CommitTask {
114109
pub commit_id: u64,
115110
pub allow_undelegation: bool,
116111
pub committed_account: CommittedAccount,
117-
fetched_account: Option<Account>,
112+
base_account: Option<Account>,
118113
}
119114

120115
impl CommitTask {
@@ -125,43 +120,49 @@ impl CommitTask {
125120
allow_undelegation: bool,
126121
committed_account: CommittedAccount,
127122
) -> Self {
128-
let chain_config =
129-
ChainConfig::local(ComputeBudgetConfig::new(1_000_000));
130-
131-
let rpc_client = RpcClient::new_with_commitment(
132-
chain_config.rpc_uri.to_string(),
133-
CommitmentConfig {
134-
commitment: chain_config.commitment,
135-
},
136-
);
137-
138123
let fetched_account = if committed_account.account.data.len()
139124
> CommitTask::COMMIT_STATE_SIZE_THRESHOLD
140125
{
126+
// TODO (snawaz): it is the most ugliest piece of code as it is making network call,
127+
// and I'll soon fix it in a separate PR that will use caching of base-accounts.
128+
use solana_rpc_client::rpc_client::RpcClient;
129+
use solana_sdk::commitment_config::CommitmentConfig;
130+
131+
use crate::{config::ChainConfig, ComputeBudgetConfig};
132+
133+
let chain_config =
134+
ChainConfig::local(ComputeBudgetConfig::new(1_000_000));
135+
136+
let rpc_client = RpcClient::new_with_commitment(
137+
chain_config.rpc_uri.to_string(),
138+
CommitmentConfig {
139+
commitment: chain_config.commitment,
140+
},
141+
);
142+
141143
rpc_client.get_account(&committed_account.pubkey).ok()
142144
} else {
143145
None
144146
};
145147

148+
println!("fetched_account: {:#?}", fetched_account);
149+
146150
Self {
147151
commit_id,
148152
allow_undelegation,
149153
committed_account,
150-
fetched_account,
154+
base_account: fetched_account,
151155
}
152156
}
153157

154-
// TODO (snawaz): it is infinitely bad implementation
155-
// as it's making a network call, but we'll fix it soon once
156-
// we start using caching and fetched accounts.
157158
pub fn is_commit_diff(&self) -> bool {
158159
self.committed_account.account.data.len()
159160
> CommitTask::COMMIT_STATE_SIZE_THRESHOLD
160-
&& self.fetched_account.is_some()
161+
&& self.base_account.is_some()
161162
}
162163

163164
pub fn create_commit_ix(&self, validator: &Pubkey) -> Instruction {
164-
if let Some(fetched_account) = self.fetched_account.as_ref() {
165+
if let Some(fetched_account) = self.base_account.as_ref() {
165166
self.create_commit_diff_ix(validator, fetched_account)
166167
} else {
167168
self.create_commit_state_ix(validator)

test-integration/test-committor-service/tests/test_delivery_preparator.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ use crate::common::{create_commit_task, generate_random_bytes, TestFixture};
1515

1616
mod common;
1717

18-
#[tokio::test]
18+
//#[tokio::test]
19+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
1920
async fn test_prepare_10kb_buffer() {
21+
println!("TestFixture::new()");
2022
let fixture = TestFixture::new().await;
23+
println!("TestFixture::new() done");
2124
let preparator = fixture.create_delivery_preparator();
2225

2326
let data = generate_random_bytes(10 * 1024);
@@ -76,7 +79,7 @@ async fn test_prepare_10kb_buffer() {
7679
);
7780
}
7881

79-
#[tokio::test]
82+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
8083
async fn test_prepare_multiple_buffers() {
8184
let fixture = TestFixture::new().await;
8285
let preparator = fixture.create_delivery_preparator();
@@ -206,7 +209,7 @@ async fn test_lookup_tables() {
206209
}
207210
}
208211

209-
#[tokio::test]
212+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
210213
async fn test_already_initialized_error_handled() {
211214
let fixture = TestFixture::new().await;
212215
let preparator = fixture.create_delivery_preparator();
@@ -288,7 +291,7 @@ async fn test_already_initialized_error_handled() {
288291
assert_eq!(account.data.as_slice(), data, "Unexpected account data");
289292
}
290293

291-
#[tokio::test]
294+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
292295
async fn test_prepare_cleanup_and_reprepare_mixed_tasks() {
293296
use borsh::BorshDeserialize;
294297

0 commit comments

Comments
 (0)