diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 824a2753..70e9cfe2 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -35,8 +35,8 @@ jobs: with: context: . platforms: linux/amd64,linux/arm64 - build-args: | - RUBY_VERSION=2.7 + # build-args: | + # RUBY_VERSION=2.7 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/ruby-unit-tests.yml b/.github/workflows/ruby-unit-tests.yml index df4372fa..ba9979f8 100644 --- a/.github/workflows/ruby-unit-tests.yml +++ b/.github/workflows/ruby-unit-tests.yml @@ -15,12 +15,12 @@ jobs: - uses: actions/checkout@v4 - name: copy config.rb file from template run: cp config/config.test.rb config/config.rb - - name: Build docker-compose - run: docker-compose build + - name: Build docker compose + run: docker compose build - name: Run unit tests run: | ci_env=`bash <(curl -s https://codecov.io/env)` - docker-compose run $ci_env -e CI --rm ${{ matrix.backend }} bundle exec rake test TESTOPTS='-v' + docker compose run $ci_env -e CI --rm ${{ matrix.backend }} bundle exec rake test TESTOPTS='-v' - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4 with: diff --git a/.gitignore b/.gitignore index ccf97ea0..0cd105fc 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ config/*.p12 config/*.json data/ projectFilesBackup/ +.bundle .ruby-version repo* *.turtle diff --git a/Dockerfile b/Dockerfile index 73e1379c..6ac0eecf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG RUBY_VERSION +ARG RUBY_VERSION=3.0 ARG DISTRO_NAME=bullseye FROM ruby:$RUBY_VERSION-$DISTRO_NAME @@ -14,10 +14,6 @@ COPY Gemfile* *.gemspec /srv/ontoportal/ncbo_cron/ WORKDIR /srv/ontoportal/ncbo_cron -# set rubygem and bundler to the last version supported by ruby 2.7 -# remove version after ruby v3 upgrade -RUN gem update --system '3.4.22' -RUN gem install bundler -v '2.4.22' RUN gem update --system RUN gem install bundler ENV BUNDLE_PATH=/srv/ontoportal/bundle diff --git a/Gemfile.lock b/Gemfile.lock index aef96992..6462aa9f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/ncbo/goo.git - revision: f01386fe55ffba39cbf5e0bf95c8e2dc18767711 + revision: f943ac33e87c55c88131c32d826ed5d39c89302c branch: master specs: goo (0.0.2) @@ -8,6 +8,7 @@ GIT pry rdf (= 1.0.8) redis + request_store rest-client rsolr sparql-client @@ -15,7 +16,7 @@ GIT GIT remote: https://github.com/ncbo/ncbo_annotator.git - revision: 63c986880aa88c9384043e6611a682434a14aba7 + revision: d46d667ec1b2343fbcdab587f1a70e763b894133 branch: master specs: ncbo_annotator (0.0.1) @@ -26,7 +27,7 @@ GIT GIT remote: https://github.com/ncbo/ontologies_linked_data.git - revision: 4dc3b1123e871b53ba9eb51983ff69c5d2c75c18 + revision: 9ab4be437ed84f5a480e7f0d8799824fcea310ae branch: master specs: ontologies_linked_data (0.0.1) @@ -46,7 +47,7 @@ GIT GIT remote: https://github.com/ncbo/sparql-client.git - revision: d418d56a6c9ff5692f925b45739a2a1c66bca851 + revision: e89c26aa96f184dbe9b52d51e04fb3d9ba998dbc branch: master specs: sparql-client (1.0.1) @@ -59,6 +60,8 @@ PATH specs: ncbo_cron (0.0.1) dante + faraday (~> 2) + faraday-follow_redirects (~> 0) goo google-analytics-data mlanett-redis-lock @@ -74,99 +77,124 @@ GEM activesupport (3.2.22.5) i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) - addressable (2.8.6) - public_suffix (>= 2.0.2, < 6.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) base64 (0.2.0) bcrypt (3.1.20) - bigdecimal (3.1.7) - builder (3.2.4) + bigdecimal (3.1.8) + builder (3.3.0) + childprocess (5.1.0) + logger (~> 1.5) coderay (1.1.3) - concurrent-ruby (1.2.3) + concurrent-ruby (1.3.4) connection_pool (2.4.1) cube-ruby (0.0.3) dante (0.2.0) date (3.3.4) declarative (0.0.20) - docile (1.4.0) + docile (1.4.1) domain_name (0.6.20240107) - email_spec (2.2.2) + email_spec (2.3.0) htmlentities (~> 4.3.3) - launchy (~> 2.1) + launchy (>= 2.1, < 4.0) mail (~> 2.7) - faraday (2.8.1) - base64 - faraday-net_http (>= 2.0, < 3.1) - ruby2_keywords (>= 0.0.4) - faraday-net_http (3.0.2) - faraday-retry (2.2.0) + faraday (2.12.0) + faraday-net_http (>= 2.0, < 3.4) + json + logger + faraday-follow_redirects (0.3.0) + faraday (>= 1, < 3) + faraday-net_http (3.3.0) + net-http + faraday-retry (2.2.1) faraday (~> 2.0) - ffi (1.16.3) - gapic-common (0.21.1) + ffi (1.17.0) + ffi (1.17.0-aarch64-linux-gnu) + ffi (1.17.0-arm64-darwin) + ffi (1.17.0-x86_64-linux-gnu) + gapic-common (0.22.0) faraday (>= 1.9, < 3.a) faraday-retry (>= 1.0, < 3.a) - google-protobuf (~> 3.18) - googleapis-common-protos (>= 1.4.0, < 2.a) - googleapis-common-protos-types (>= 1.11.0, < 2.a) - googleauth (~> 1.9) - grpc (~> 1.59) - google-analytics-data (0.6.0) + google-protobuf (>= 3.25, < 5.a) + googleapis-common-protos (~> 1.6) + googleapis-common-protos-types (~> 1.15) + googleauth (~> 1.11) + grpc (~> 1.65) + google-analytics-data (0.6.1) google-analytics-data-v1beta (>= 0.11, < 2.a) google-cloud-core (~> 1.6) - google-analytics-data-v1beta (0.12.0) + google-analytics-data-v1beta (0.13.1) gapic-common (>= 0.21.1, < 2.a) google-cloud-errors (~> 1.0) - google-apis-analytics_v3 (0.15.0) - google-apis-core (>= 0.14.0, < 2.a) - google-apis-core (0.14.1) + google-apis-analytics_v3 (0.16.0) + google-apis-core (>= 0.15.0, < 2.a) + google-apis-core (0.15.1) addressable (~> 2.5, >= 2.5.1) googleauth (~> 1.9) - httpclient (>= 2.8.1, < 3.a) + httpclient (>= 2.8.3, < 3.a) mini_mime (~> 1.0) + mutex_m representable (~> 3.0) retriable (>= 2.0, < 4.a) - rexml - google-cloud-core (1.7.0) + google-cloud-core (1.7.1) google-cloud-env (>= 1.0, < 3.a) google-cloud-errors (~> 1.0) - google-cloud-env (2.1.1) + google-cloud-env (2.2.1) faraday (>= 1.0, < 3.a) google-cloud-errors (1.4.0) - google-protobuf (3.25.3) - google-protobuf (3.25.3-x86_64-linux) - googleapis-common-protos (1.5.0) - google-protobuf (~> 3.18) + google-protobuf (4.28.2) + bigdecimal + rake (>= 13) + google-protobuf (4.28.2-aarch64-linux) + bigdecimal + rake (>= 13) + google-protobuf (4.28.2-arm64-darwin) + bigdecimal + rake (>= 13) + google-protobuf (4.28.2-x86_64-linux) + bigdecimal + rake (>= 13) + googleapis-common-protos (1.6.0) + google-protobuf (>= 3.18, < 5.a) googleapis-common-protos-types (~> 1.7) grpc (~> 1.41) - googleapis-common-protos-types (1.14.0) - google-protobuf (~> 3.18) - googleauth (1.11.0) + googleapis-common-protos-types (1.16.0) + google-protobuf (>= 3.18, < 5.a) + googleauth (1.11.1) faraday (>= 1.0, < 3.a) google-cloud-env (~> 2.1) jwt (>= 1.4, < 3.0) multi_json (~> 1.11) os (>= 0.9, < 2.0) signet (>= 0.16, < 2.a) - grpc (1.62.0) - google-protobuf (~> 3.25) + grpc (1.66.0) + google-protobuf (>= 3.25, < 5.0) + googleapis-common-protos-types (~> 1.0) + grpc (1.66.0-aarch64-linux) + google-protobuf (>= 3.25, < 5.0) googleapis-common-protos-types (~> 1.0) - grpc (1.62.0-x86_64-linux) - google-protobuf (~> 3.25) + grpc (1.66.0-arm64-darwin) + google-protobuf (>= 3.25, < 5.0) + googleapis-common-protos-types (~> 1.0) + grpc (1.66.0-x86_64-linux) + google-protobuf (>= 3.25, < 5.0) googleapis-common-protos-types (~> 1.0) htmlentities (4.3.4) http-accept (1.7.0) - http-cookie (1.0.5) + http-cookie (1.0.7) domain_name (~> 0.5) httpclient (2.8.3) i18n (0.9.5) concurrent-ruby (~> 1.0) - json (2.7.1) - json_pure (2.7.1) - jwt (2.8.1) + json (2.7.2) + json_pure (2.7.2) + jwt (2.9.3) base64 - launchy (2.5.2) + launchy (3.0.1) addressable (~> 2.8) + childprocess (~> 5.0) libxml-ruby (5.0.3) - logger (1.6.0) + logger (1.6.1) macaddr (1.7.2) systemu (~> 2.6.5) mail (2.8.1) @@ -174,17 +202,21 @@ GEM net-imap net-pop net-smtp - method_source (1.0.0) - mime-types (3.5.2) + method_source (1.1.0) + mime-types (3.6.0) + logger mime-types-data (~> 3.2015) - mime-types-data (3.2024.0305) + mime-types-data (3.2024.1001) mini_mime (1.1.5) minitest (4.7.5) mlanett-redis-lock (0.2.7) redis multi_json (1.15.0) + mutex_m (0.2.0) + net-http (0.4.1) + uri net-http-persistent (2.9.4) - net-imap (0.4.10) + net-imap (0.4.16) date net-protocol net-pop (0.1.2) @@ -194,44 +226,47 @@ GEM net-smtp (0.5.0) net-protocol netrc (0.11.0) - oj (3.16.3) + oj (3.16.6) bigdecimal (>= 3.0) + ostruct (>= 0.2) omni_logger (0.1.4) logger os (1.1.4) + ostruct (0.6.0) parseconfig (1.1.2) pony (1.13.1) mail (>= 2.0) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - public_suffix (5.0.4) - rack (3.0.10) + public_suffix (6.0.1) + rack (3.1.7) rack-test (2.1.0) rack (>= 1.3) - rake (13.1.0) + rake (13.2.1) rdf (1.0.8) addressable (>= 2.2) - redis (5.1.0) - redis-client (>= 0.17.0) - redis-client (0.21.1) + redis (5.3.0) + redis-client (>= 0.22.0) + redis-client (0.22.2) connection_pool representable (3.2.0) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) + request_store (1.7.0) + rack (>= 1.4) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) retriable (3.1.2) - rexml (3.2.6) + rexml (3.3.8) rsolr (2.6.0) builder (>= 2.1.2) faraday (>= 0.9, < 3, != 2.0.0) ruby-xxHash (0.4.0.2) - ruby2_keywords (0.0.5) rubyzip (2.3.2) rufus-scheduler (2.0.24) tzinfo (>= 0.3.22) @@ -247,7 +282,7 @@ GEM simplecov-cobertura (2.1.0) rexml simplecov (~> 0.19) - simplecov-html (0.12.3) + simplecov-html (0.13.1) simplecov_json_formatter (0.1.4) sys-proctable (1.3.0) ffi (~> 1.1) @@ -259,11 +294,14 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) uber (0.1.0) + uri (0.13.1) uuid (2.3.9) macaddr (~> 1.0) - webrick (1.8.1) + webrick (1.8.2) PLATFORMS + aarch64-linux + arm64-darwin-22 ruby x86_64-linux @@ -294,4 +332,4 @@ DEPENDENCIES webrick BUNDLED WITH - 2.4.22 + 2.5.20 diff --git a/bin/ncbo_ontology_delete b/bin/ncbo_ontology_delete index ff36e6d6..f3bdbc16 100755 --- a/bin/ncbo_ontology_delete +++ b/bin/ncbo_ontology_delete @@ -12,6 +12,9 @@ config_exists = File.exist?(File.expand_path('../../config/config.rb', __FILE__) abort("Please create a config/config.rb file using the config/config.rb.sample as a template") unless config_exists require_relative '../config/config' +# do not send notifications to ontology owners when running this script +LinkedData.settings.enable_notifications = false + require 'optparse' options = {} opt_parser = OptionParser.new do |opts| diff --git a/bin/ncbo_ontology_index b/bin/ncbo_ontology_index index 746d8d95..706b0741 100755 --- a/bin/ncbo_ontology_index +++ b/bin/ncbo_ontology_index @@ -12,6 +12,9 @@ config_exists = File.exist?(File.expand_path('../../config/config.rb', __FILE__) abort("Please create a config/config.rb file using the config/config.rb.sample as a template") unless config_exists require_relative '../config/config' +# do not send notifications to ontology owners when running this script +LinkedData.settings.enable_notifications = false + platform = "local" if LinkedData.settings.goo_host.include? "stage" platform = "stage" diff --git a/bin/ncbo_ontology_metrics b/bin/ncbo_ontology_metrics index 6497314b..ca714ba5 100755 --- a/bin/ncbo_ontology_metrics +++ b/bin/ncbo_ontology_metrics @@ -12,6 +12,10 @@ config_exists = File.exist?(File.expand_path('../../config/config.rb', __FILE__) abort("Please create a config/config.rb file using the config/config.rb.sample as a template") unless config_exists require_relative '../config/config' +# do not send notifications to ontology owners when running this script +LinkedData.settings.enable_notifications = false + + platform = "local" if LinkedData.settings.goo_host.include? "stage" platform = "stage" diff --git a/bin/ncbo_ontology_process b/bin/ncbo_ontology_process index 879e749d..4c0a8957 100755 --- a/bin/ncbo_ontology_process +++ b/bin/ncbo_ontology_process @@ -13,6 +13,9 @@ abort("Please create a config/config.rb file using the config/config.rb.sample a require_relative '../config/config' require 'optparse' +# do not send notifications to ontology owners when running this script +LinkedData.settings.enable_notifications = false + options = {all: false} opt_parser = OptionParser.new do |opts| # Set a banner, displayed at the top of the help screen. diff --git a/bin/ncbo_ontology_property_index b/bin/ncbo_ontology_property_index index 0d908777..12eb05e1 100755 --- a/bin/ncbo_ontology_property_index +++ b/bin/ncbo_ontology_property_index @@ -12,6 +12,9 @@ config_exists = File.exist?(File.expand_path('../../config/config.rb', __FILE__) abort("Please create a config/config.rb file using the config/config.rb.sample as a template") unless config_exists require_relative '../config/config' +# do not send notifications to ontology owners when running this script +LinkedData.settings.enable_notifications = false + platform = "local" if LinkedData.settings.goo_host.include? "stage" platform = "stage" diff --git a/bin/ncbo_ontology_pull b/bin/ncbo_ontology_pull index be3e08de..45720492 100755 --- a/bin/ncbo_ontology_pull +++ b/bin/ncbo_ontology_pull @@ -14,6 +14,9 @@ require_relative '../lib/ncbo_cron' require_relative '../config/config' require 'optparse' +# do not send notifications to ontology owners when running this script +LinkedData.settings.enable_notifications = false + ontology_acronym = '' opt_parser = OptionParser.new do |opts| opts.on('-o', '--ontology ACRONYM', 'Ontology acronym to pull if new version exist') do |acronym| @@ -30,9 +33,8 @@ opt_parser.parse! logger = Logger.new($stdout) logger.info "Starting ncbo pull"; logger.flush -puller = NcboCron::Models::OntologyPull.new begin - puller.do_ontology_pull(ontology_acronym, logger: logger, enable_pull_umls: true) + NcboCron::Helpers::OntologyHelper.do_ontology_pull(ontology_acronym, logger: logger, enable_pull_umls: true) rescue StandardError => e logger.error e.message logger.flush diff --git a/docker-compose.yml b/docker-compose.yml index 44c9fda4..066debce 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,9 +2,9 @@ x-app: &app build: context: . args: - RUBY_VERSION: '2.7' + RUBY_VERSION: '3.0' # Increase the version number in the image tag every time Dockerfile or its arguments is changed - image: ncbo_cron:0.0.2 + image: ncbo_cron:0.0.3 environment: &env BUNDLE_PATH: /srv/ontoportal/bundle # default bundle config resolves to /usr/local/bundle/config inside of the container @@ -93,7 +93,7 @@ services: - 4store solr-ut: - image: ontoportal/solr-ut:0.1.0 + image: ontoportal/solr-ut:0.2.0 healthcheck: test: ["CMD-SHELL", "curl -sf http://localhost:8983/solr/term_search_core1/admin/ping?wt=json | grep -iq '\"status\":\"OK\"}' || exit 1"] start_period: 3s @@ -105,7 +105,7 @@ services: image: ontoportal/mgrep:0.0.2 platform: linux/amd64 healthcheck: - test: ["CMD", "nc", "-z", "-v", "localhost", "55556"] + test: ["CMD", "nc", "-z", "-v", "127.0.0.1", "55556"] start_period: 3s interval: 10s timeout: 5s diff --git a/lib/ncbo_cron/obofoundry_sync.rb b/lib/ncbo_cron/obofoundry_sync.rb index 2437a9f3..23dd6e8d 100644 --- a/lib/ncbo_cron/obofoundry_sync.rb +++ b/lib/ncbo_cron/obofoundry_sync.rb @@ -1,7 +1,6 @@ -require 'base64' -require 'json' -require 'net/http' -require 'uri' +require 'faraday' +require 'faraday/follow_redirects' +require 'multi_json' module NcboCron module Models @@ -9,9 +8,6 @@ class OBOFoundrySync def initialize @logger = Logger.new(STDOUT) - @oauth_token = Base64.decode64(NcboCron.settings.git_repo_access_token) - @graphql_uri = URI.parse("https://api.github.com/graphql") - @request_options = { use_ssl: @graphql_uri.scheme == "https" } end def run @@ -19,24 +15,25 @@ def run map = get_ids_to_acronyms_map onts = get_obofoundry_ontologies - @logger.info("Found #{onts.size} OBO Library ontologies") + @logger.info("Found #{onts.size} OBO Foundry ontologies") - # Are any OBO Library ontologies missing from BioPortal? + # Are any OBO Foundry ontologies missing from BioPortal? missing_onts = [] - active_onts = onts.reject { |ont| ont.key?("is_obsolete") } + active_onts = onts.reject { |ont| ont.key?('is_obsolete') } + @logger.info("#{active_onts.size} OBO Foundry ontologies are currently active") active_onts.each do |ont| - if not map.key?(ont["id"]) + if not map.key?(ont['id']) missing_onts << ont - @logger.info("Missing OBO Library ontology: #{ont['title']} (#{ont['id']})") + @logger.info("Missing OBO Foundry ontology: #{ont['title']} (#{ont['id']})") end end - # Have any of the OBO Library ontologies that BioPortal hosts become obsolete? + # Have any of the OBO Foundry ontologies that BioPortal hosts become obsolete? obsolete_onts = [] - ids = active_onts.map{ |ont| ont["id"] } + ids = active_onts.map{ |ont| ont['id'] } obsolete_ids = map.keys - ids obsolete_ids.each do |id| - ont = onts.find{ |ont| ont["id"] == id } + ont = onts.find{ |ont| ont['id'] == id } @logger.info("Deprecated OBO Library ontology: #{ont['title']} (#{ont['id']})") obsolete_onts << ont end @@ -45,49 +42,19 @@ def run end def get_ids_to_acronyms_map - query = "query { - repository(name: \"ncbo.github.io\", owner: \"ncbo\") { - object(expression: \"master:oboids_to_bpacronyms.json\") { - ... on Blob { - text - } - } - } - }" - - response = issue_request(query) - JSON.parse(response) + response = Faraday.get('https://ncbo.github.io/oboids_to_bpacronyms.json') + MultiJson.load(response.body) end def get_obofoundry_ontologies - query = "query { - repository(name: \"OBOFoundry.github.io\", owner: \"OBOFoundry\") { - object(expression: \"master:registry/ontologies.jsonld\") { - ... on Blob { - text - } - } - } - }" - - response = issue_request(query) - ont_registry = JSON.parse(response) - ont_registry["ontologies"].to_a - end - - def issue_request(query) - request = Net::HTTP::Post.new(@graphql_uri) - request["Authorization"] = "bearer #{@oauth_token}" - request.body = JSON.dump({"query" => query}) - - response = Net::HTTP.start(@graphql_uri.hostname, @graphql_uri.port, @request_options) do |http| - http.request(request) + conn = Faraday.new do |faraday| + faraday.response :follow_redirects + faraday.adapter Faraday.default_adapter end + response = conn.get('http://purl.obolibrary.org/meta/ontologies.jsonld') - parsed = JSON.parse(response.body) - parsed.dig("data", "repository", "object", "text") + MultiJson.load(response.body)['ontologies'] end - end end end diff --git a/ncbo_cron.gemspec b/ncbo_cron.gemspec index c8faa03d..e48d7e7f 100644 --- a/ncbo_cron.gemspec +++ b/ncbo_cron.gemspec @@ -15,6 +15,8 @@ Gem::Specification.new do |gem| gem.require_paths = ["lib"] gem.add_dependency("dante") + gem.add_dependency('faraday', '~> 2') + gem.add_dependency('faraday-follow_redirects', '~> 0') gem.add_dependency("goo") gem.add_dependency("google-analytics-data") gem.add_dependency("mlanett-redis-lock") diff --git a/test/test_case.rb b/test/test_case.rb index 75bb0454..cae57cda 100644 --- a/test/test_case.rb +++ b/test/test_case.rb @@ -107,4 +107,11 @@ def _run_suite(suite, type) ## # Base test class. Put shared test methods or setup here. class TestCase < MiniTest::Unit::TestCase + # http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Dynamic.2C_private_or_ephemeral_ports + def self.unused_port + server = TCPServer.new('127.0.0.1', 0) + port = server.addr[1] + server.close + port + end end diff --git a/test/test_ontology_pull.rb b/test/test_ontology_pull.rb index 8ac6dce6..112fd11b 100644 --- a/test/test_ontology_pull.rb +++ b/test/test_ontology_pull.rb @@ -9,7 +9,7 @@ class TestOntologyPull < TestCase def self.before_suite ont_path = File.expand_path("../data/ontology_files/BRO_v3.2.owl", __FILE__) file = File.new(ont_path) - @@port = Random.rand(55000..65535) # http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Dynamic.2C_private_or_ephemeral_ports + @@port = TestCase.unused_port @@url = "http://localhost:#{@@port}/" @@thread = Thread.new do server = WEBrick::HTTPServer.new(Port: @@port) @@ -103,7 +103,7 @@ def test_remote_pull_parsing_action end def test_pull_error_notification - server_port = Random.rand(55000..65535) + server_port = TestCase.unused_port begin thread = Thread.new do diff --git a/test/test_scheduler.rb b/test/test_scheduler.rb index 58808ea5..db28f26e 100644 --- a/test/test_scheduler.rb +++ b/test/test_scheduler.rb @@ -1,9 +1,7 @@ -require 'minitest/unit' -MiniTest::Unit.autorun +require_relative 'test_case' +# require_relative '../lib/ncbo_cron' -require_relative '../lib/ncbo_cron' - -class TestScheduler < MiniTest::Unit::TestCase +class TestScheduler < TestCase def test_scheduler begin logger = Logger.new($stdout) @@ -19,7 +17,8 @@ def test_scheduler # Create a simple TCPServer to listen from the fork require 'socket' listen_string = "" - port = Random.rand(55000..65535) # http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Dynamic.2C_private_or_ephemeral_ports + port = TestCase.unused_port + socket_server = Thread.new do server = TCPServer.new(port) loop { @@ -69,7 +68,7 @@ def test_scheduler_locking # Create a simple TCPServer to listen from the fork require 'socket' listen_string = "" - port = Random.rand(55000..65535) # http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Dynamic.2C_private_or_ephemeral_ports + port = TestCase.unused_port socket_server = Thread.new do server = TCPServer.new(port) loop { @@ -104,8 +103,8 @@ def test_scheduler_locking assert job1_thread.alive? assert job2_thread.alive? - assert listen_string.include?("JOB1") - refute listen_string.include?("JOB2") + assert_includes listen_string, "JOB1" + refute_includes listen_string, "JOB2" job1_thread.kill job1_thread.join refute job1_thread.alive?