Debugging OntoPortal
The first edition of this guide assumes that one is running Linux and that the IDE of choice is RubyMine. As more than one person edits this document will become more generic and where it is known it will be indicated that a given solution is RubyMine or Linux specific.I also tend to favour running the Infrastructure in docker to avoid lengthy installs to seeup a developement environment.
Running stuff
In order to expect anything to work one needs to have the infrastructure running. This can be quickly provided by docker but some of out developers have it running on their development machines. The docker solution will be described later in this note (infrastructure through docker) and the install option may be later described by other developers.
Tests for a project are often run as rake tasks:
bundler exex rake test
The ncbo project has a bunch of other useful rake tasks that we will find documentation for later.
The ontologies rest services are run via rackup from the ontologies_api project:
bundler exec rackup
The difference betweeen rackup and rake is that rackup is optimized for web services. Each service is implemented as a call
interface call where call takes one argument. I am not yet sure where rackup is configured.
Rbenv and versions of Ruby
Unfortunately, one cannot simply install the latest version of ruby and expect that things would work. One needs to choose the appropriate version of ruby. Ruby is too essential to the development to see how to run it only in docker. Thus it is useful to have a tool that allows one to select and use a specific version of ruby, possibly on a project specific basis. We often use rbenv for this though there are other tools that are useful (and possibly more secure) for this purpose. A discussion of the installation and use of rbenv can be found here.
Running from the command line with docker
There are many docker-compoee files that create a running infrastructure. I use the one in the bioportal-config project (which for this purpose is unfortunately private). This docker image set provides
- solr
- redis
- memcached
- mgrep and
- 4store
which is sufficient to run to run all the ReST services of BioPortal.
Now on the command line you should be able to run commands such as
bundle install
bundler exec rake
to run the tests.
Running from RubyMine
Running from RubyMine is, at least in theory, simple once you have the code One catch which may explain why this is sometimes tricky for me is that you need to be sure that RubyMine is running the same versions of ruby and bundler as the command line environment. The ruby version can be set here:
Settings->Languages & Frameworks->Ruby SDK and Gems
but I think (maybe) the bundler version needs to be set on the RubyMine command line.
To convince RubyMine to run the program, you need to tell it what to do with a Run/Debug configuration as follows:
This tells RubyMine to run the configuration as a rake task (default) in the ‘goo’ projects directory, with the argument
TEST=test/test_chunks_write.rb
and the environment
TESTOPTS="--name=test_reentrant_queries"
This is a real runnable from my work on the goo test and it says to run the test_reentrant_queries test from the file test/test_chunks_write.rb. It took a little bit of figuring out but it was very useful to pick a particular test.
Troubleshooting: Bundler version problems
A key responsibity of the bundler is to define the dependant libraries and to execute things in that context. Therefore, when you get exceptions that do not seem related to a BioPortal bug that indicate a problem with depe dent ruby code then it suggeeets a problem with the bundler. These exceptions often aee geneeated by “require” statements. An example of such an exception may be generated by running “rake” without the bundler:
[tredmond@Titan goo]$ rake
Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
From:
/home/tredmond/BioPortal/projects/goo/test/test_case.rb:12:in `<top (required)>'
/home/tredmond/BioPortal/projects/goo/test/test_basic_persistence.rb:1:in `require_relative'
/home/tredmond/BioPortal/projects/goo/test/test_basic_persistence.rb:1:in `<top (required)>'
/home/tredmond/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:21:in `block in <main>'
/home/tredmond/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in `select'
/home/tredmond/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in `<main>'
MiniTest::Unit.autorun is now Minitest.autorun. From /home/tredmond/BioPortal/projects/goo/test/test_case.rb:13:in `<top (required)>'
Traceback (most recent call last):
11: from /home/tredmond/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in `<main>'
10: from /home/tredmond/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in `select'
9: from /home/tredmond/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:21:in `block in <main>'
8: from /home/tredmond/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
7: from /home/tredmond/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
6: from /home/tredmond/BioPortal/projects/goo/test/test_basic_persistence.rb:1:in `<top (required)>'
5: from /home/tredmond/BioPortal/projects/goo/test/test_basic_persistence.rb:1:in `require_relative'
4: from /home/tredmond/BioPortal/projects/goo/test/test_case.rb:15:in `<top (required)>'
3: from /home/tredmond/BioPortal/projects/goo/test/test_case.rb:15:in `require_relative'
2: from /home/tredmond/BioPortal/projects/goo/lib/goo.rb:4:in `<top (required)>'
1: from /home/tredmond/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:146:in `require'
/home/tredmond/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:146:in `require': cannot load such file -- sparql/client (LoadError)
rake aborted!
Command failed with status (1)
Tasks: TOP => default => test
(See full trace by running task with --trace)
[tredmond@Titan goo]$
The end of this exception is very similar to something that I saw when running the rake command inside ruby. To fix this I ran the following commands inside a RubyMine terminal:
gem install bundler
bundler init
bundle install
The init command may be important - in spite of the fact that it generated an error suggesting that it did nothing - becuase things did not seem to work without it,
Case Study: Bundler version problems
I recently saw the same exception that had bothered me so much before:
/bin/bash -c "env RBENV_VERSION=2.7.0 /home/tredmond/.rbenv/libexec/rbenv exec ruby /home/tredmond/.rbenv/versions/2.7.0/bin/rake default TEST=test/test_chunks_write.rb"
Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
From:
/home/tredmond/BioPortal/projects/goo/test/test_case.rb:19:in `<top (required)>'
/home/tredmond/BioPortal/projects/goo/test/test_chunks_write.rb:1:in `require_relative'
/home/tredmond/BioPortal/projects/goo/test/test_chunks_write.rb:1:in `<top (required)>'
/home/tredmond/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:21:in `block in <main>'
/home/tredmond/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in `select'
/home/tredmond/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in `<main>'
MiniTest::Unit.autorun is now Minitest.autorun. From /home/tredmond/BioPortal/projects/goo/test/test_case.rb:20:in `<top (required)>'
Traceback (most recent call last):
11: from /home/tredmond/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in `<main>'
10: from /home/tredmond/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in `select'
9: from /home/tredmond/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:21:in `block in <main>'
8: from /home/tredmond/.rbenv/versions/2.7.0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
7: from /home/tredmond/.rbenv/versions/2.7.0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
6: from /home/tredmond/BioPortal/projects/goo/test/test_chunks_write.rb:1:in `<top (required)>'
5: from /home/tredmond/BioPortal/projects/goo/test/test_chunks_write.rb:1:in `require_relative'
4: from /home/tredmond/BioPortal/projects/goo/test/test_case.rb:22:in `<top (required)>'
3: from /home/tredmond/BioPortal/projects/goo/test/test_case.rb:22:in `require_relative'
2: from /home/tredmond/BioPortal/projects/goo/lib/goo.rb:4:in `<top (required)>'
1: from /home/tredmond/.rbenv/versions/2.7.0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
/home/tredmond/.rbenv/versions/2.7.0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- sparql/client (LoadError)
rake aborted!
Command failed with status (1)
Tasks: TOP => default => test
(See full trace by running task with --trace)
Process finished with exit code 1
I did several iterations of looking at the bundler version in settings (I eyentually managed to set it there) and executing bundle initialization commands on the ruby and machine command line to no avail. A new version of the bundler had become available. Then I realized that I had removed goo and restored it with git clone. So I restarted RubyMine (twice - the first one did not take somehow) and all became well. I was left not totally understanding what had happened (why twice?).