Sha256: ad042d8d384809566e0a6b0eca901aa13847f08d491f072371ad41f4f6b325ab

Contents?: true

Size: 1.19 KB

Versions: 8

Compression:

Stored size: 1.19 KB

Contents

require "fileutils"
require "timeout"

RSpec.describe Relaton::DbCache do
  it "creates default caches" do
    cache_path = File.expand_path("~/.relaton/cache")
    FileUtils.mv cache_path, "relaton1/cache", force: true
    FileUtils.rm_rf %w(relaton)
    Relaton::Db.init_bib_caches(
      global_cache: true, local_cache: "", flush_caches: true,
    )
    expect(File.exist?(cache_path)).to be true
    expect(File.exist?("relaton")).to be true
    FileUtils.mv "relaton1/cache", cache_path if File.exist? "relaton1"
  end

  it "write same file by concurent processes" do
    dir = "testcache/iso"
    FileUtils.mkdir_p dir unless File.exist? dir
    file_name = File.join dir, "iso_123.xml"
    file = File.open file_name, File::RDWR | File::CREAT, encoding: "UTF-8"
    file.flock File::LOCK_EX
    command = <<~RBY
      require "relaton"
      cache = Relaton::DbCache.new "testcache"
      cache["ISO(ISO 123)"] = "test 1"
    RBY
    pid = spawn RbConfig.ruby, "-e #{command}"
    sleep 0.1
    file.write "test 2"
    file.flock File::LOCK_UN
    file.close
    Process.waitpid pid, 0
    expect($?.exitstatus).to eq 0
    expect(File.read(file_name)).to eq "test 1"
    FileUtils.rm_rf "testcache"
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
relaton-1.14.1 spec/relaton/db_cache_spec.rb
relaton-1.14.0 spec/relaton/db_cache_spec.rb
relaton-1.13.0 spec/relaton/db_cache_spec.rb
relaton-1.12.4 spec/relaton/db_cache_spec.rb
relaton-1.12.3 spec/relaton/db_cache_spec.rb
relaton-1.8.pre4 spec/relaton/db_cache_spec.rb
relaton-1.8.pre3 spec/relaton/db_cache_spec.rb
relaton-1.8.pre2 spec/relaton/db_cache_spec.rb