bjowes / cypress-ntlm-auth

Windows authentication plugin for Cypress
MIT License
55 stars 10 forks source link

What does Env Variable allowMultipleInstances do? #124

Closed MSIH closed 4 years ago

MSIH commented 4 years ago

We are using Jenkins to run Cypress test with cypress-ntlm-auth. But when more than one jenkins jobs run at the same time, most of the cypress test fail because the cypress-ntlm-auth proxy has been terminated. We found the allowMultipleInstancesin the code and are trying to understand if this will help us.

bjowes commented 4 years ago

Hi!

allowMultipleInstances could enable multiple ntlm-proxy instances to run in parallel, but there might be other issues with the cypress part of the plugin. The current design is that the ports of ntlm-proxy are stored in a temporary file. If a new instance is started, this file is overwritten. The cypress part of the plugin validates the startup config against this file, so timing between startup of parallel jobs could cause that validation to fail.

I think the whole startup procedure would need to be rewritten to properly support multiple instances. I'll give this some thought, I know there are other users who would like to run the plugin in parallel.

creage commented 4 years ago

@bjowes It would be really nice to have an option to run multiple, independent proxies at once. This would help testing interaction scenarios of different users, like chats, etc.

bjowes commented 3 years ago

@creage - multiple instances is now supported, released in 3.0.0

creage commented 3 years ago

@bjowes thanks for your effort, but I'm not sure I'm clear how to run such setup. Could you please provide a simple example of running two NTLM sessions in parallel?

P.S. I also see you've changed your API a bit, which affected me in not good way - I'm not using Cypress to run my tests, but PlayWright. And I was using your fantastic library to run a proxy for my tests. And now I need another hour or two to reverse engineer your changes :). I would be really happy if you could keep your 'standalone' API stable and somehow more documented. But thanks anyway for amazing work.

bjowes commented 3 years ago

Hi @creage

Yes, the Node module API has been changed a bit. I try to preserve it, but this is a major release and I think one should expect the possibility of API changes in major releases. You are right though - I forgot to mention this clearly in the breaking changes in the docs, and the Node module API is lacking documentation in the README. I did add comments to the API methods, so with intellisense you should be able to see what they do.

If I'm not missing something, the Node module API was just extended. You can still use the run command just like before

const cypressNtlm = require('cypress-ntlm-auth');
await cypressNtlm.run(options)

I have added the ability to open cypress in headed mode (using the open method) and convenience methods to convert command line arguments to options argumentsToOptions(process.argv) and a similar method to find if cypress run or cypress open was intended argumentsToCypressMode(process.argv)

Could you clarify what is failing when you use the API?

As for running multiple instances - let me clarify that the plugin does not support parallelisation internally. It just supports isolated instances. Earlier, only one ntlm-proxy could run at a time, meaning that only one instance of cypress-ntlm was possible. Now the default is that cypress-ntlm starts its own proxy (just like the Node module API always did), each proxy uses its own config, and it is possible to run multiple such instances. A simple example would be if you just open up two command prompts in your cypress project dir and do npx cypress-ntlm open in both of them. You will now have two instances of cypress with NTLM support, that can execute tests independently of each other. Many CI environments have support for parallell test execution which can then utilise this feature. Let me know if something is unclear.

creage commented 3 years ago

Unfortunately, simple

await cypressNtlm.run(options)

doesn't work for me, as it checks if I have Cypress installed, and I don't, and it fails.

So, for v2.3.0 I was emulating the run method, pushing my custom environment, and calling ntlm.proxy.main.js to start, and ntlm.proxy.exit.main.js to exit. But you've changed wrappers around this structure a bit, so I'll have to adapt my scripts.

What I was thinking of, is an option to have a core proxy implementation as an accessible package, which could be later consumed/wrapped by any adapter - like Cypress, Selenium, PlayWright etc.

And I'll give a try on multiple instances once I get my head around these latest changes - thank you!

bjowes commented 3 years ago

Ah, if you want to use only the proxy (without cypress) I can see that some of the changes has come in your way. I wasn't aware that anyone was using it this way. I could expose a proxyStart and proxyStop method in the Node module API that can be used when you want to run only the proxy. Would that make sense to you?

creage commented 3 years ago

That would be super nice from your side! And, will your methods support picking random port and all the goodies of new multi-instance approach?

Ideally, I'd like to have a way to start a new proxy (with new user/credentials) giving me back address:port I'll use in browser instance; the way to stop a particular proxy; and the way to stop them all (if multiple were started). Could we have such API please?

bjowes commented 3 years ago

@creage - since this discussion is not really related to the original issue anymore I have created #138 to continue the discussion of an API for ntlm-proxy.