Skip to content
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

Breaking out of nested cursor in subprocess block #42

Open
chrisconley opened this issue Mar 15, 2012 · 5 comments
Open

Breaking out of nested cursor in subprocess block #42

chrisconley opened this issue Mar 15, 2012 · 5 comments
Assignees

Comments

@chrisconley
Copy link

I'm having some trouble with breaking out to a main cursor from within a cursor in a subprocess block. I've set up two test cases to illustrate what's going on below. Am I trying to do something unsupported/wacky or would you expect both of these test cases to pass?

Thanks!
Chris

  def test_nested_break_passes
    pdef = Ruote.process_definition do
      define "sub1" do
        # do some stuff
        apply # apply isn't in a new cusor - process works fine
        #do some more stuff
      end

      cursor :tag => "main" do
        sub1 do
          bravo
        end
        sub1 do
          alpha
        end
      end

      charly
    end

    alpha = @dashboard.register_participant :alpha, Ruote::StorageParticipant
    bravo = @dashboard.register_participant :bravo, Ruote::StorageParticipant
    charly = @dashboard.register_participant :charly, Ruote::StorageParticipant


    wfid = @dashboard.launch(pdef)
    wait_for(:bravo)
    wi = bravo.first
    wi.fields['__command__'] = [ 'break', "main" ]

    @dashboard.reply(wi)
    wait_for(:charly)
  end

  def test_nested_break_hangs
    pdef = Ruote.process_definition do
      define "sub1" do
        cursor do
          # do some stuff
          apply # apply is now nested in a cursor
          # do some more stuff
        end
      end

      cursor :tag => "main" do
        sub1 do
          bravo
        end
        sub1 do
          alpha
        end
      end

      charly
    end

    alpha = @dashboard.register_participant :alpha, Ruote::StorageParticipant
    bravo = @dashboard.register_participant :bravo, Ruote::StorageParticipant
    charly = @dashboard.register_participant :charly, Ruote::StorageParticipant


    wfid = @dashboard.launch(pdef)
    wait_for(:bravo)
    wi = bravo.first
    wi.fields['__command__'] = [ 'break', "main" ]

    @dashboard.reply(wi)
    wait_for(:charly)
  end
@jmettraux
Copy link
Owner

Investigating...

@jmettraux
Copy link
Owner

I want to try and fix it, I want to make it work like we both expect, but it's not that easy. I'll get back to it later today.

Thanks for reporting it!

@jmettraux
Copy link
Owner

I simplified the hanging test:

    def test_nested_break_does_not_reach_ref

      pdef = Ruote.process_definition do

        cursor :tag => 'main' do
          cursor do
            bravo
          end
          cursor do
            alpha
          end
        end

        charly
      end

      alpha = @dashboard.register_participant :alpha, Ruote::StorageParticipant
      bravo = @dashboard.register_participant :bravo, Ruote::StorageParticipant
      charly = @dashboard.register_participant :charly, Ruote::StorageParticipant


      wfid = @dashboard.launch(pdef)
      wait_for(:bravo)
      wi = bravo.first
      wi.fields['__command__'] = [ 'break', 'main' ]

      @dashboard.reply(wi)
      r = @dashboard.wait_for('dispatch')

      assert_equal 'charly', r['participant_name']
    end

There is a different behaviour between passing a command via a command expression (http://ruote.rubyforge.org/exp/command.html) and passing the command by setting "command" in the workitem. I'm still thinking how to make them uniform or introduce the distinction between direct messages and passing messages. I hope that by tomorrow I'll have a decent solution.

Thanks again.

@chrisconley
Copy link
Author

Hi John, thanks very much.

I started thinking I could accomplish what I wanted to do with :break_if => "${f:flagged}" in the "main" cursor instead of sending the command from the participant, which by itself didn't work. By accident, at one point I had both the :break_if and wi.fields['__command__'] = [ 'break', 'main' ] which actually worked.

I haven't had time to recreate the simplified test case, but wanted to mention it in case it helps things.

Thanks!
Chris

@ghost ghost assigned jmettraux Mar 16, 2012
@chrisconley
Copy link
Author

Hi John,

From the other thread I was able to simplify the failing test case a bit:

  def test_nested_rewind_hangs
    pdef = Ruote.process_definition do
      cursor :tag => "main" do
        cursor do
          bravo
        end
        alpha
      end

      charly
    end

    @dashboard.register '.+', Ruote::StorageParticipant

    wfid = @dashboard.launch(pdef)

    wait_for_and_proceed(@dashboard, :bravo) {|wi|  wi.fields["__command__"] = ["break", "main"] }

    wait_for(:charly)
  end

  def wait_for_and_proceed(dashboard, participant_name, &block)
    wait_for(participant_name)
    wi = dashboard.storage_participant.by_participant(participant_name.to_s).first
    yield wi if block_given?
    dashboard.storage_participant.proceed(wi)
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants