how can I speed up ruby on rails tests on windows? - ruby-on-rails

I've started learning to use Ruby on Rails running on Windows 7, and the time to run tests is painful I'm wondering if I can speed it up.
Right now I am using the default test framework (inheriting from ActionController), with a SQLite database and the webrick web server.
While unit and functional tests report a runtime of less than 2 seconds, from the time I run the tests from the command-line to completion is actually 40 secounds.
A friend recommended I use guard. That looks like it will help start the tests as soon as I save, but it seems like the real cost is starting up the webserver or database. I wonder if it might be better to set up apache or mysql and use those locally instead.
Anyhow, what tips do people have for speeding up ruby on rails tests on windows? I tried running the tests on Amazon EC2 linux micro instance (again with webrick and sqlite) and there was significant startup time (though I did not time it).
I tried "rake test --trace". There was a significant pause:
Immediately before the first line of output
Between outputing "Execute environment" and "Execute db:abort_if_pending_migrations"
Between "Execute test:units" and "Run options:"
The first pause seems worse.

Your best bet is to use spork which now works in Windows. It runs on windows by pre-populating a pool of ready processes (referred to as the “magazine” strategy). The result is that webserver startup time is dramatically reduced.
If running rails on Windows is really the bottleneck then you can run a virtual machine using VirtualBox and run an instance of Ubuntu and work on your rails projects in the VM.

Related

Ruby on rails scheduled tasks

This is my first time scheduling a task and I am not sure of the best implementation (or the proper implementation).
My Goal:
I have a ruby on rails 4 app setup with twilio and deployed on Heroku. I want the app to automatically text all of my users once a week with a customized text message (which is written and created by information in the database).
From research I have come down to the following Gems: Whenever and Rufus-Scheduler.
I believe that both these gems can get the Job done, but upon reading on the Rufus' docs: "please note: rufus-scheduler is not a cron replacement" I got stuck trying to understand if what I want is indeed a cron job or a "Rufus-Scheduler".
I am left with the following questions: What is a cron job and when is the appropriate time to use it? Why is Rufus-Scheduler not a cron replacement and what does it do differently? Which one should I use?
About Cron:
Cron is name of program which does scheduled tasks on nix systems. what Scheduled Tasks are in Windows, Cron does something similar for Linux at the conceptual level.Cron is one of the most useful tool in Linux or UNIX like operating systems. The cron service (daemon) runs in the background and constantly checks the /etc/crontab file, and /etc/cron./ directories. It also checks the /var/spool/cron/ directory.
For Scheduling tasks on Heroku
Good news is that on Heroku there is a thing called Scheduler which is an add-on for running jobs on your app at scheduled time intervals, much like cron in a traditional server environment. so you really don't need to fiddle/player with cron or gems like whenever. just use the Scheduler addon on Heroku.
For More info see: https://devcenter.heroku.com/articles/scheduler
A cron job is a program run on an automated time schedule, using the cron software.
Rufus-Scheduler is different from cron because it runs inside of Ruby processes.
For what you're describing I believe either would be fine.
rufus-scheduler is not a cron replacement
can be expanded to "rufus-scheduler was never written as a drop-in replacement for cron". The bigger message is "you are a developer and as a developer you should know the environment you inherit and the tools it comes with. You should know when to use them, when to imitate them, when to replace them."
Rufus-scheduler understands the "* * * * *" syntax of Cron. This has led some people to say "rufus-scheduler tries to be a Cron replacement". It could better be formulated as "some people have abused rufus-scheduler instead of thinking (knowing) that old faithful Cron would have been better in that situation".
To become a good developer you should think seriously about some *nix sysadmin skills, else you'll be a pain to work with. It can be as easy as "install, run and manage a linux box in a VirtualBox in your system".
A rufus-scheduler schedule runs in a Ruby process. In a vanilla world, one runs rufus-scheduler in the same Ruby process that services http requests (Rails or Sinatra web application), and, oh, oops, the schedules don't run when the application doesn't run.
Cron is a service provided by your *nix operating system. Other applications and services on your host rely on it. Cron reads its crontab and runs the script indicated in it at the given times. Thanks to the excellent Whenever, Cron can be told to run scripts in your Rails application.
This might interest you as well: https://devcenter.heroku.com/articles/clock-processes-ruby
whenever allows you to write ruby code that would be transformed in a crontab file, which is a file specifying a set of commands and a frequency for each command. This file is used by cron.
rufus-scheduler is pure ruby, you write ruby and jobs are running in ruby, for example inside your application loop calling scheduler.join, or in another thread calling ruby your/rufus_scheduler_script.rb.
In my opinion they do the same things, with cron you are using a linux command, but I don't see any other difference.
There are other options too, in my experience I have had problems with rufus-scheduler, and whenever (they did not find classes in my Rails app, but maybe was just a quirk), on the other side clockwork worked for me.

Rails acceptance tests - run Foreman

My application runs properly using Faye, Redis, Resque and other services, that I am starting every time with Foreman. Now I am writing acceptance tests with Capybara+RSpec, and I wonder how I could start Foreman (or even Faye alone) with Capybara in spec_helper to test live features.
One option is to not depend on these services in your tests. I know redis and resque have "mock" counterparts that behave like these services without actually needing to run them. Some services might not have a "mock" version (I can't find one for Faye), so you may just need to run them in the background.
if you are using jenkins as the CI server, you can start the foreman before rspec started.

Use JRuby (or IronRuby) to boots performance of Rails on Windows?

I am currently developing Rails on a Windows laptop, but it runs very slowly. Would it be worthwhile to try running rails on JRuby or IronRuby to speed up performance?
If you are using ruby 1.9.2 or 1.9.3 don't worry about that, it's fast as others or even faster. Also notice that java applications tends to use a lot of memmory.
The thing is that in development your app is reloaded in each request, in production it will be loaded only at server startup.
To test it try to run your app in production environment, and maybe you should use other server like thin.
thin start -e production
Also if this does not help. Maybe you should think about cache, create new indexes or even change to a better data base (maybe you are using sqlite). But I doubt that changing to Jruby or IronRuby will help you that much.

Can I run grails integration & functional tests against a running server?

I'm finding the feedback look pretty slow when running integration and functional tests in Grails. Is there a way I can run them against a running server instance while I'm writing the tests, to save on server startup time each time they're executed?
You can use grails interactive which does what you want without starting a server. It starts a JVM and keeps it running and you can use it to run unit and integration tests. Keep in mind that you'll eventually run out of memory and need to restart periodically. See http://docs.grails.org/latest/guide/gettingStarted.html#usingInteractiveMode
Also in 1.3.5 you can run functional tests against a running server. Use the baseUrl attribute described in section 9.3 at http://grails.org/doc/latest/
there's an option --baseUrl
e.g.
grails test-app --baseUrl=http://localhost:8080/myapp/
that runs tests against a running instance, one draw back is that the slate isn't wiped clean after a test, so if your test writes to the db, uploads a file, or some other permanent change to the application, then you may have to do some tearDown.
This is briefly documented at the end of the function testing section of the grails docs
http://grails.org/doc/latest/guide/testing.html#functionalTesting
It's useful for writing/debugging functional tests
I'm using Grails 1.3.5 and the EasyB plugin for stories in the context of functional tests.
Take a look at http://padcom13.blogspot.com/2010/10/grails-easyb-and-selenium.html for step-by-step instructions.

How to make/monitor/deploy daemon processes in JRuby

I'm currently porting a Rails App currently using REE to JRuby so I can offer an easy-to-install JRuby alternative.
I've bundled the app into a WAR file using Bundler which I'm currently deploying to GlassFish. However, this app has a couple of daemon processes and it would be ideal if these could be part of the WAR file, and potentially monitored by Glassfish (if possible).
I've looked at QuartzScheduler, and while meets my needs for a couple of things, I have a daemon process that must execute every 20 seconds as it's polling the database for any delayed mail to send.
If anyone can provide any insight as to how best to set up daemon processes in a JRuby/Java/Glassfish environment any help will be greatly appreciated! :)
One way to daemonize a JRuby process is to use akuma framework (on *nix) or others.
I would rather use cronjobs (schedulling) rather than daemons as they are less error-proned, daemons can leak memory, can stop on errors etc. Check jruby-quartz and quartz_scheduler
EDIT
If one uses Torquebox it offers support for services and scheduling.

Resources