Response Injection and Behaviors

374 views
Skip to first unread message

Bruce Maginnis

unread,
May 20, 2021, 6:31:47 AM5/20/21
to mountebank-discuss
Hi,

Do behaviors work when you are using Response Injection?

I've tried applying a wait behavior with Response injection but it does not appear to honour the delay

"behaviors": [
{
"wait": 10000
}
]

Thanks,
B

Brandon Byars

unread,
May 20, 2021, 9:37:01 AM5/20/21
to Bruce Maginnis, mountebank-discuss
Yes, should do. I just tested with the imposter below. Can you confirm you've got the right JSON structure for the injection?

{
"protocol": "http",
"port": 3000,
"stubs": [
{
"responses": [{
"inject": "function (config) { return { body: 'Hello, world!' }; }",
"behaviors": [
{ "wait": 10000 }
]
}]
}
]
}

--
You received this message because you are subscribed to the Google Groups "mountebank-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mountebank-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mountebank-discuss/e5638b2f-006e-400a-9ed3-e0321ff533e7n%40googlegroups.com.

Bruce Maginnis

unread,
May 20, 2021, 10:00:01 AM5/20/21
to mountebank-discuss
Hi,
Thanks for the prompt reply.

I am using tcp, if that makes a difference and I think I have json correct

"stubs": [
    {
        "responses": [
            {
                "inject": "function Response (config) { return { data: 'grSxtDm4MDmysjAwMLSxsjAwMLEwMJyc0mVx9WXzdKB34fOg8HJvY2Xz82XkoPP1Y2Nl8/Nm9Wxs+S6cnJycnDAwMDAwMJwesTAwsR2xsjO0NTa3uDkwsbIztDU2t7g5oKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoJwesTAwsh2qqqqqqjAwMDCxMDA2sbGxtLGyNTaxObS3srfMw0I1QsPSqqqqqqqqnAM=' } ;}",
                "behaviors": [
                    { "wait": 10000 }
                ]
            }]
    }]

B

Brandon Byars

unread,
May 20, 2021, 10:43:14 AM5/20/21
to Bruce Maginnis, mountebank-discuss
Using tcp shouldn't make a difference, but does make it harder to test. This command line call, for example, would not see a wait, but that's because of netcat, not mountebank:

> echo "Test" | nc localhost 3000

By default, netcat closes the client socket after sending the message, and I have not found a cross-platform way of using netcat to keep the socket open until the server responds. I wrote this test using JS libraries to make the tcp call and it behaves as expected:

it.only('test', async function () {
this.timeout(15000);
const stub = {

responses: [{
inject: "function Response (config) { return { data: 'grSxtDm4MDmysjAwMLSxsjAwMLEwMJyc0mVx9WXzdKB34fOg8HJvY2Xz82XkoPP1Y2Nl8/Nm9Wxs+S6cnJycnDAwMDAwMJwesTAwsR2xsjO0NTa3uDkwsbIztDU2t7g5oKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoJwesTAwsh2qqqqqqjAwMDCxMDA2sbGxtLGyNTaxObS3srfMw0I1QsPSqqqqqqqqnAM=' } ;}",
behaviors: [{ wait: 10000 }]
}]
        },
request = { protocol: 'tcp', port: port, stubs: [stub] },
start = new Date();
await api.createImposter(request);

await tcp.send('!', port);

const time = new Date() - start;
console.log(time);
});


  tcp imposter
    POST /imposters with stubs
10021
      ✓ test (10022ms)


  1 passing (10s)

Bruce Maginnis

unread,
May 20, 2021, 11:51:55 AM5/20/21
to mountebank-discuss
Hi,

I took your exact stub definition above and applied to my imposter.

But that response came back instantly when using the test client of our system. No delay at all

The only other difference my imposter would have would be mode:binary

I'll continue to have a play around and see if I'm missing something else, but if you've any other pointers or things to try, that would be great

Thanks,
B

Bruce Maginnis

unread,
May 21, 2021, 3:07:13 AM5/21/21
to mountebank-discuss
Hey,

To close the loop on this one, I was reviewing the code in the accompanying book and noticed that the syntax was slightly different.

Perhaps its the version I am using but _behaviors worked

"stubs": [
{
"responses": [{
"inject": "function Response (config) { return { data: 'grSxtDm4MDmysjAwMLSxsjAwMLEwMJyc0mVx9WXzdKB34fOg8HJvY2Xz82XkoPP1Y2Nl8/Nm9Wxs+S6cnJycnDAwMDAwMJwesTAwsR2xsjO0NTa3uDkwsbIztDU2t7g5oKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoJwesTAwsh2qqqqqqjAwMDCxMDA2sbGxtLGyNTaxObS3srfMw0I1QsPSqqqqqqqqnAM=' } ;}",
"_behaviors": { "wait": 10000 }
}]
}]

Brandon Byars

unread,
May 21, 2021, 10:13:49 AM5/21/21
to Bruce Maginnis, mountebank-discuss
That'll do it. The syntax changed recently and is backwards compatible to the old syntax, but that's obviously not true in reverse. Thanks for reporting back.

Reply all
Reply to author
Forward
0 new messages