diff --git a/lib/autoload/kuroko2/workflow/task/fork.rb b/lib/autoload/kuroko2/workflow/task/fork.rb index 00181900..98d144d0 100644 --- a/lib/autoload/kuroko2/workflow/task/fork.rb +++ b/lib/autoload/kuroko2/workflow/task/fork.rb @@ -43,9 +43,9 @@ def extract_child_nodes end def create_child_token(child_node:, env: {}) - attributes = token.attributes.except('id', 'uuid', 'script', 'path', 'message', 'created_at', 'updated_at') - attributes = attributes.merge(uuid: SecureRandom.uuid, parent: token, script: child_node.to_script, path: '/') - attributes['context']['ENV'] = (attributes['context']['ENV'] || {}).merge(env) + attributes = token.attributes.except('id', 'uuid', 'script', 'path', 'message', 'created_at', 'updated_at', 'context') + attributes = attributes.merge(uuid: SecureRandom.uuid, parent: token, script: child_node.to_script, path: '/', context: token.context.deep_dup) + attributes[:context]['ENV'] = (attributes[:context]['ENV'] || {}).merge(env) Token.create!(attributes).tap do |created| fork_children_ids << created.id diff --git a/spec/workflow/engine_spec.rb b/spec/workflow/engine_spec.rb index abc005ee..346c0a62 100644 --- a/spec/workflow/engine_spec.rb +++ b/spec/workflow/engine_spec.rb @@ -126,6 +126,7 @@ module Kuroko2::Workflow parallel_fork: 3 noop: noop1 noop: noop2 + noop: noop3 EOF end @@ -173,6 +174,13 @@ module Kuroko2::Workflow expect(parallel_tokens.map(&:path)).to all(eq('/0-sequence/1-noop')) expect(parallel_tokens.map(&:status_name)).to all(eq('finished')) + subject.process(token) + expect(token.path).to eq '/2-noop' + expect(token.status_name).to eq 'working' + expect(token.context['ENV']['GLOBAL_ENV']).to eq('g') + expect(token.context['ENV']['KUROKO2_PARALLEL_FORK_SIZE']).to be_nil + expect(token.context['ENV']['KUROKO2_PARALLEL_FORK_INDEX']).to be_nil + subject.process_all expect(Kuroko2::Token.all.count).to eq 0 end