Yii2 codeception command did not finished properly - yii2

Now I know this Command Did Not Finished Properly means that some die or exit statement occurs somewhere in the way of the test but is there is way to ignore it and see the result from that test ? I'm trying simple basic login test ( I am total newbie in tests ) and I am not sure if the test passes like an expected. It looks like so:
public function validLoginUser(FunctionalTester $I)
{
$I->amOnPage('/admin/user/login');
$I->fillField('login-form[login]', 'toma');
$I->fillField('login-form[password]', '9110033969');
$I->click('Log in');
$I->see('Статистики', 'h4.text-white');
}
I am pretty sure that the test pass successuly. The form is the dektrium extension Yii2 login form. Nothing changed on it. Or maybe the problem is that I am trying to test someone else's code? If it's not how can I see the result? Thank you in advance and I am sorry for the confusing question.

"Command Did Not Finished Properly" message is printed by shutdown handler, there is no way to resume test execution from that point.
If your codebase uses die a lot, you could use PhpBrowser module to test over HTTP instead of using Yii2 module which executes application code in the same process.

Related

Printing error messages from console instead of closing shiny app

I have a shiny app that runs a monte carlo simulation with 500 replications. To do this, I use a for loop and call a function from another package to run the simulation, and then I save the data. The shiny app then produces the results using renderTable.
It is possible that the user could mistakenly enter something that would cause one or more of the replications to fail to converge, triggering a stop in the function I'm calling. If this happens, there is nothing to render in a table. In R, I get a nice error message from the package telling me that the model failed to converge. However, in Shiny, the app just force closes.
I'm currently using tryCatch and showNotification to display this notification in the app (see below):
observeEvent(input$go,
tryCatch({
simulation_results()
},
error = function(err){
showNotification(paste0(err), type = 'err')
})
)
It works well, but the problem is that it causes the app to take 6x longer to run (it goes from ~1.5 min to ~10 min). I think this is because it's trying to catch and show the notification from every individual replication in the for loop. The app also still does close; it just displays the error first (which I do appreciate).
Is there a [faster] way to get shiny to print error messages from the console instead of closing the app?
I was thinking of validate, but I don't know how it would work - what I really need is something like
validate(need("no error message in the console")). I tried using validate(need(simulation_results(),geterrmessage()) to see if it would simply print the last error message if there were no simulation results, but the app shuts down once it gets to the stop error in the function.
Also, I'm using flexdashboard if that changes anything.

Cypress test scenario logging in Via Auth0

I've started using Cypress to test our front End Internal Application (being built using Angular5), which uses Auth0 as login authentication.
I'm a QA with NO experience of any sort of coding, so I was quite pleased when I managed to get a few tests working (and passing).
However I have hit a stumbling block. Even though I can use Cypress to test that the Auth0 login works; when the login is successful it is not opening the application in the test as it would if I were manually testing.
Below is my test that runs the Auth0 authentication test.
describe('My Login Test', function (){
it('Visit Risk App Landing Page', function (){
const typedText = 'user-email-address'
cy.visit('http://localhost:3000/workflow')
cy.get('button').click()
cy.get('input.auth0-lock-input').first()
.type(typedText)
.should('have.value', typedText)
cy.get('button').click()
cy.url().should('eq','http://localhost:3000/workflow')
})
})
I'm also trying to create a function where I can call Auth0 and store the response so I don't have to run a login scenario before every tests that runs for the rest of the application, but as I said I have no coding experience and I've found that creating a function is far different to creating a test as that shown above.
If anyone could offer any suggestions/tips/clues, they would all be appreciated.
can't help you with your first question. But as for extracting your login code for reusablitity you could create a cypress command https://docs.cypress.io/api/cypress-api/custom-commands.html#Syntax
Cypress.Commands.add('login', (email, password) => {
cy.visit('http://localhost:3000/workflow')
cy.get('button').click()
cy.get('input.auth0-lock-input').first()
.type(email)
cy.get('button').click()
cy.url().should('eq','http://localhost:3000/workflow')
})
Then from within your tests you could call it like:
cy.login('some-email', 'somepassword')

my nodejs script is not exiting on its own after successful execution

I have written a script to update my db table after reading data from db tables and solr. I am using asyn.waterfall module. The problem is that the script is not getting exited after successful completion of all operations. I have used db connection pool also thinking that may be creating the script to wait infinitly.
I want to put this script in crontab and if it will not exit properly it would be creating a hell lot of instances unnecessarily.
I just went through this issue.
The problem with just using process.exit() is that the program I am working on was creating handles, but never destroying them.
It was processing a directory and putting data into orientdb.
so some of the things that I have come to learn is that database connections need to be closed before getting rid of the reference. And that process.exit() does not solve all cases.
When my project processed 2,000 files. It would get down to about 500 left, and the extra handles would have filled up the available working memory. Which means it would not be able to continue. Therefore never reaching the process.exit at the end.
On the other hand, if you close the items that are requesting the app to stay open, you can solve the problem at its source.
The two "Undocumented Functions" that I was able to use, were
process._getActiveHandles();
process._getActiveRequests();
I am not sure what other functions will help with debugging these types of issues, but these ones were amazing.
They return an array, and you can determine a lot about what is going on in your process by using these methods.
You have to tell it when you're done, by calling
process.exit();
More specifically, you'll want to call this in the callback from async.waterfall() (the second argument to that function). At that point, all your asynchronous code has executed, and your script should be ready to exit.
EDIT: As pointed out by #Aaron below, this likely has to do with something like a database connection being active, and not allowing the node process to end.
You can use the node module why-is-node-running:
Run npm install -D why-is-node-running
Add import * as log from 'why-is-node-running'; in your code
When you expect your program to exit, add a log statement:
afterAll(async () => {
await app.close();
log();
})
This will print a list of open handles with a stacktrace to find out where they originated:
There are 5 handle(s) keeping the process running
# Timeout
/home/maf/dev/node_modules/why-is-node-running/example.js:6 - setInterval(function () {}, 1000)
/home/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()
# TCPSERVERWRAP
/home/maf/dev/node_modules/why-is-node-running/example.js:7 - server.listen(0)
/home/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()
We can quit the execution by using:
connection.destroy();
If you use Visual Studio code, you can attach to an already running Node script directly from it.
First, run the Debug: Attached to Node Process command:
When you invoke the command, VS Code will prompt you which Node.js process to attach to:
Your terminal should display this message:
Debugger listening on ws://127.0.0.1:9229/<...>
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Then, inside your debug console, you can use the code from The Lazy Coder’s answer:
process._getActiveHandles();
process._getActiveRequests();

$m->comp is returning infinite recursive call error

I am having trouble using HTML::Mason's $m->comp to redirect from one view to another.
There is a file say file1.mi which has embedded HTML code in this file1.mi I am using $m->comp to redirect to file2.mi.
But in the webpage whenever file1.mi is loaded it prints the footer multiple times and in the logs i am getting the errors
Nested page framework application dispatch detected, this usage is not
fully supported and may result in unexpected behavior
and
Error: APPLICATION CONTEXT ERROR (RENDER): 32 levels deep in component
stack (infinite recursive call?)
. Here is the script which i am using for redirecting from file1.mi
return $m->comp('/page-framework/dispatch.mi', applicationPath =>'/gp/tradein/omc', viewID => 'file2.mi', %ARGS);
I am using this script in file1.mi before it renders the webpage -- i.e. before any HTML scripts are executed.
I am kinda new to Mason, if you have queries regarding this please go ahead.
It looks like that your file1.mi gets loaded and rendered, then file2.mi gets executed and it in infinite loop.
Please, show us more code, it is not possible to debug with that small details.
What do you in the web server logs? Please, paste some example from loglines too.
Regards,
It should be your dispatcher dispatch.mi that is calling file1 or file2. Deciding that you want to go elsewhere after the request has already been dispatched seems like the logic is in the wrong place.

sfErrorNotifierPlugin: The "default" context does not exist

I have installed the sfErrorNotifierPlugin. When both options reportErrors/reportPHPErrors reportPHPWarnings/reportWarnings are set to false, everything is ok. But I want to catch PHP exceptions and warnings to receive E-mails, but then all my tasks fail, including clear-cache. After few hours of tests I'm 100% sure that the problem is with set_exception_handler/set_error_handler.
There's a similar question:
sfErrorNotifierPlugin on symfony task but the author there is having problems with a custom task. In my case, even built-in tasks fail.
I haven't used sfErrorNotifierPlugin, but I have run into 'The “default” context does not exist.' messages before. It happens when a call is made to sfContext::getInstance() and the context simply doesn't exist. I've had this happen a lot from within custom tasks. One solution is to add sfContext::createInstance() before the call to sfContext::getInstance(). This will ensure that a context exists.
There's an interesting blog post on 'Why sfContext::getInstance() is bad' that goes into more detail - http://webmozarts.com/2009/07/01/why-sfcontextgetinstance-is-bad/
Well, the problem could not be solved this way, unfortunately. Using sfErrorNotifierPlugin, I have enabled reporting PHP warning/errors (apart from symfony exceptions) and this resulted in huge problems, e.g. built-in tasks such as clear-cache failed.
The solution I chose was to load the plugin only in non-task mode (project configuration class):
public function setup()
{
$this->enableAllPluginsExcept('sfPropelPlugin');
if ('cli' == php_sapi_name()) $this->disablePlugins('sfErrorNotifierPlugin');
}
WHen a task is executed, everything works normally. When an app is fired from the browser, emails are sent when exception/warning occurs (maybe someone will find it useful).
Arms has explained the problem correctly. But usually context does not exist when executing backend/maintenance tasks on the console. And it is easier if you handle the condition yourself.
Check, if you really need the context?
If you do, what exactly do you need it for?
Sometimes you only want a user to populate a created_by field. You can work around by hard-coding a user ID.
If you want to do something more integrated, create a page (which will have a context) and trigger the task from there.
you can test the existance of the instance before doing something inside a class. Like:
if(sfContext::hasInstance())
$this->microsite_id = sfContext::getInstance()->getUser()->getAttribute('active_microsite');
I've been experiencing the same problem using the plugin sfErrorNotifier.
In my specific case, I noticed a warning was raised:
Warning: ob_start(): function '' not found or invalid function name in /var/www/ncsoft_qa/lib/vendor/symfony/lib/config/sfApplicationConfiguration.class.php on line 155
Notice: ob_start(): failed to create buffer in /var/www/ncsoft_qa/lib/vendor/symfony/lib/config/sfApplicationConfiguration.class.php on line 155
So, checking the file: sfApplicationConfiguration.class.php class, line 155,
I've replaced the ' ' for a null, then the warnings disappears, and also the error!
ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : ''); bad
ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : null); good