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

Feature: Support Recv option to requeue a failed match message #119

Open
jsccast opened this issue Aug 6, 2021 · 0 comments
Open

Feature: Support Recv option to requeue a failed match message #119

jsccast opened this issue Aug 6, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@jsccast
Copy link
Member

jsccast commented Aug 6, 2021

Say you want to recv two messages without respect to order. For example, you want to recv "queso" and also recv "nachos", but you don't know the order that those messages will arrive (and you don't care). Currently you might have to resort to using a guard and perhaps additional state, and that work is tedious.

Instead, recv could maybe support a requeueonfail option, which would queue a message that failed a match so that the message could be re-received later. Example use:

spec:
  phases:
    phase1:
      steps:
        - '$include<include/mock.yaml>'
        - run: |
            // A hack to randomize the order in which we say and hear
            // things.
            
            var t = now(),
                n = t[t.length - 5]; // A digit from nanoseconds.
                flip = n % 2 == 0;
                
            test.Bindings["?first"]  =  flip ? "nachos": "queso";
            test.Bindings["?second"] = !flip ? "nachos": "queso";
        - ingest:
            doc: |
              Send a message to ourselves.  Use our randomly-chosen
              "first" value.
            payload: '{"want":"?first"}'
        - ingest:
            doc: |
              Send another message to ourselves.  Use the other value.
            payload: '{"want":"?second"}'
        - recv:
            pattern: '{"want":"queso"}'
            requeueonfail: true
        - recv:
            pattern: '{"want":"nachos"}'
            requeueonfail: true

In this example, we'll hear "nachos" and then "queso" or we'll near "queso" and then "nachos". We'd like to verify we hear both, but we do not want to specify the order or resort to guards. The requestonfail option would tell recv to queue a message that fails the match rather than to drop it. That way the second recv will see a message that the first recv rejected.

It's not hard to imagine this behavior causing a lot of confusion; however, it seems useful in certain narrow circumstances.

@jsccast jsccast added the enhancement New feature or request label Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant