Skip to content

Commit

Permalink
Merge pull request #128 from itkq/prop
Browse files Browse the repository at this point in the history
Prevent from propagating env vars at outside of fork task scope
  • Loading branch information
Takuya Kosugiyama authored Jun 3, 2019
2 parents 0a86a4d + 174918f commit 1e962c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/autoload/kuroko2/workflow/task/fork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/workflow/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ module Kuroko2::Workflow
parallel_fork: 3
noop: noop1
noop: noop2
noop: noop3
EOF
end

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1e962c7

Please sign in to comment.