Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving test consistency for DSpace and DescribeIndexer #714

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ node_modules
# https://vitejs.dev/guide/env-and-mode.html#env-files
*.local
.yardoc/

spec/fixtures/migration/dspace_migration.csv
11 changes: 11 additions & 0 deletions app/lib/describe_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ def index_one(json)
traject_indexer.complete
end

def client
@client ||= Blacklight.default_index.connection
end

def delete!(query:)
client.delete_by_query(query)
client.commit
client.optimize
client
end

private

def rss_http_response
Expand Down
11 changes: 11 additions & 0 deletions app/lib/dspace_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,15 @@ def self.index(_options)
i.index
i
end

def client
@client ||= Blacklight.default_index.connection
end

def delete!(query:)
client.delete_by_query(query)
client.commit
client.optimize
client
end
end
61 changes: 43 additions & 18 deletions app/models/version_footer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# rubocop:disable Style/ClassVars
class VersionFooter
DEPLOYMENT_LOGFILE_COL_NUMBER = 7
REVISIONS_LOG_COL = 3
DEFAULT_SHA = "Unknown SHA"

@@stale = true
@@git_sha = nil
Expand All @@ -31,29 +33,52 @@ def self.reset!
@@git_sha = nil
@@branch = nil
@@version = nil
# @@stale = true # potentially add this to prevent @@stale from retaining state from prior test

@@local_sha = nil
@@revisions = nil

@@git_sha = nil
@@revisions_head = nil
@@revisions_log = nil
end

def self.stale?
return false if @@stale == false
# Only read the file when version information is stale
if File.exist?(revision_file)
local_sha = File.read(revision_file).chomp.gsub(/\)$/, '')
@@stale = local_sha != git_sha
else
@@stale = true
end
@@stale
def self.revisions
return unless File.exist?(revision_file)

@@revisions ||= File.read(revision_file).chomp
end

def self.local_sha
return unless revisions

@@local_sha ||= revisions.gsub(/\)$/, '')
end

def self.revisions_log
return unless File.exist?(revisions_logfile)

content = `tail -1 #{revisions_logfile}`.chomp
elements = content.split(" ")
return if elements.length < REVISIONS_LOG_COL

element = elements[REVISIONS_LOG_COL]
@@revisions_log ||= element.gsub(/\)$/, '')
end

def self.revisions_head
return unless Rails.env.development? || Rails.env.test?

@@revisions_head ||= `git rev-parse HEAD`.chomp
end

def self.git_sha
@@git_sha ||= if File.exist?(revisions_logfile)
`tail -1 #{revisions_logfile}`.chomp.split(" ")[3].gsub(/\)$/, '')
elsif Rails.env.development? || Rails.env.test?
`git rev-parse HEAD`.chomp
else
"Unknown SHA"
end
@@git_sha ||= revisions_log || revisions_head || DEFAULT_SHA
end

def self.stale?
return false unless local_sha

local_sha != git_sha
end

def self.tagged_release?
Expand Down
2 changes: 0 additions & 2 deletions spec/fixtures/migration/dspace_migration.csv

This file was deleted.

8 changes: 6 additions & 2 deletions spec/models/version_footer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

# rubocop:disable RSpec/ExampleLength
RSpec.describe VersionFooter do
before do
described_class.reset!
end

describe "info" do
context "with stale information" do
before do
Expand Down Expand Up @@ -44,9 +48,9 @@
described_class.revisions_logfile = Pathname.new(fixture_paths.first).join("revisions_rollback.log").to_s
described_class.reset!
end
xit "detects current information" do
it "detects current information" do
info = described_class.info
expect(info[:stale]).to be false # may want to reconsider what state stale should be
expect(info[:stale]).to be true
expect(info[:sha]).to eq "to"
expect(info[:branch]).to eq "rolled"
expect(info[:version]).to eq "(Deployment date could not be parsed from: deploy rolled back to release 20211210150445\n.)"
Expand Down
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

ENV['RAILS_ENV'] ||= 'test'
ENV['RACK_ENV'] ||= 'test'

require 'spec_helper'
require File.expand_path('../config/environment', __dir__)
Expand Down
24 changes: 22 additions & 2 deletions spec/requests/catalog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
let(:indexer) do
DspaceIndexer.new(dspace_fixtures)
end

before do
indexer.index
end

after do
indexer.delete!(query: "*:*")
end

describe "GET /doi/:doi" do
let(:doi) { "doi:10.1088/0029-5515/57/1/016034" }
let(:document_id) { "84912" }
Expand Down Expand Up @@ -69,8 +74,7 @@
let(:indexer) { DescribeIndexer.new(rss_url: rss_url_string) }

before do
Blacklight.default_index.connection.delete_by_query("*:*")
Blacklight.default_index.connection.commit
indexer.delete!(query: "*:*")
stub_request(:get, "https://pdc-describe-prod.princeton.edu/describe/works.rss")
.to_return(status: 200, body: rss_feed)
stub_request(:get, "https://pdc-describe-prod.princeton.edu/describe/works/6.json")
Expand All @@ -87,6 +91,22 @@
follow_redirect!
expect(response.body).to include("test title")
end

describe "#show" do
it "shows the catalog" do
document = SolrDocument.new(id: "doi-10-34770-r75s-9j74")
get "/catalog/#{document.id}", params: { format: "json" }
expect(response.status).to eq(200)
end
end

describe "#bibtex" do
it "returns citations" do
document = SolrDocument.new(id: "doi-10-34770-r75s-9j74")
get "/catalog/#{document.id}/bibtex", params: { id: document.id }
expect(response.status).to eq(200)
end
end
end
end

Expand Down
2 changes: 0 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

ENV['RACK_ENV'] ||= 'test'

require "coveralls"
Coveralls.wear!

Expand Down