Skip to content

Commit

Permalink
Add divergence test
Browse files Browse the repository at this point in the history
  • Loading branch information
afsalthaj committed Jan 4, 2025
1 parent 5914079 commit 6bbba25
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions integration-tests/tests/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,65 +1556,72 @@ async fn fork_worker_4(deps: &EnvBasedTestDependencies, _tracing: &Tracing) {
assert!(error.contains("WorkerNotFound"));
}


#[test]
#[tracing::instrument]
#[timeout(120000)]
async fn fork_worker_divergence(deps: &EnvBasedTestDependencies, _tracing: &Tracing) {
async fn fork_worker_no_divergence_until_fork_point(
deps: &EnvBasedTestDependencies,
_tracing: &Tracing,
) {
let component_id = deps.store_component("environment-service").await;

let source_worker_id = WorkerId {
component_id: component_id.clone(),
worker_name: "foo".to_string(),
};

let env = deps
let _ = deps
.invoke_and_await(&source_worker_id, "golem:it/api.{get-environment}", vec![])
.await
.unwrap();

// The worker name is foo
check!(
env == vec![Value::Result(Ok(Some(Box::new(Value::List(vec![
Value::Tuple(vec![
Value::String("GOLEM_WORKER_NAME".to_string()),
Value::String("foo".to_string())
]),
Value::Tuple(vec![
Value::String("GOLEM_COMPONENT_ID".to_string()),
Value::String(format!("{}", component_id))
]),
Value::Tuple(vec![
Value::String("GOLEM_COMPONENT_VERSION".to_string()),
Value::String("0".to_string())
]),
])))))]
);
let expected = Value::Tuple(vec![Value::Result(Ok(Some(Box::new(Value::List(vec![
Value::Tuple(vec![
Value::String("GOLEM_WORKER_NAME".to_string()),
Value::String("foo".to_string()),
]),
Value::Tuple(vec![
Value::String("GOLEM_COMPONENT_ID".to_string()),
Value::String(format!("{}", component_id)),
]),
Value::Tuple(vec![
Value::String("GOLEM_COMPONENT_VERSION".to_string()),
Value::String("0".to_string()),
]),
])))))]);

let target_worker_id = WorkerId {
component_id: component_id.clone(),
worker_name: "forked-foo".to_string(),
};

// We fork the worker post the completion and see if oplog corresponding to environment value
// has the same value as foo
// and it shouldn't be unless divergence is fixed.

let oplog = deps.get_oplog(&source_worker_id, OplogIndex::INITIAL).await;

dbg!(oplog);
// has the same value as foo. As far as the fork cut off point is post the completion, there
// shouldn't be any divergence for worker information even if forked worker name
// is different from the source worker name
let _ = deps
.fork_worker(
&source_worker_id,
&target_worker_id,
OplogIndex::from_u64(14),
OplogIndex::from_u64(7),
)
.await;

let result = deps
.get_oplog(&target_worker_id, OplogIndex::from_u64(7))
.await;

let result = deps.search_oplog(&target_worker_id, "G1001").await;
assert_eq!(result.len(), 1);

assert_eq!(result.len(), 4); // two invocations for G1002 and two log messages
let entry = result.first().unwrap().clone();

match entry {
PublicOplogEntry::ExportedFunctionCompleted(parameters) => {
assert_eq!(parameters.response.value, expected);
}
_ => panic!("Expected ExportedFunctionCompleted"),
};
}

#[test]
Expand Down

0 comments on commit 6bbba25

Please sign in to comment.