|
53 | 53 | expect(processed).to eq true |
54 | 54 | end |
55 | 55 | end |
| 56 | + |
| 57 | + it "refreshes gem specification cache after waiting for lock" do |
| 58 | + build_repo2 do |
| 59 | + build_gem "myrack", "1.0.0" |
| 60 | + end |
| 61 | + |
| 62 | + gemfile <<-G |
| 63 | + source "https://gem.repo2" |
| 64 | + gem "myrack" |
| 65 | + G |
| 66 | + |
| 67 | + # First, install the gem so it's available |
| 68 | + bundle "install" |
| 69 | + expect(out).to include("Installing myrack") |
| 70 | + |
| 71 | + # Queue for thread-safe communication |
| 72 | + lock_acquired = Queue.new |
| 73 | + can_release_lock = Queue.new |
| 74 | + install_output = Queue.new |
| 75 | + |
| 76 | + # Thread holds lock (simulating another bundle process that just finished installing) |
| 77 | + thread = Thread.new do |
| 78 | + Bundler::ProcessLock.lock(default_bundle_path) do |
| 79 | + # Signal that we have the lock |
| 80 | + lock_acquired << true |
| 81 | + # Wait until main thread signals we can release |
| 82 | + can_release_lock.pop |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + # Wait for thread to acquire lock |
| 87 | + lock_acquired.pop |
| 88 | + |
| 89 | + # Start another install in a thread - it will wait for the lock |
| 90 | + install_thread = Thread.new do |
| 91 | + bundle "install", verbose: true |
| 92 | + install_output << out |
| 93 | + end |
| 94 | + |
| 95 | + # Give subprocess time to start and begin waiting for lock |
| 96 | + sleep 0.5 |
| 97 | + |
| 98 | + # Signal thread to release the lock |
| 99 | + can_release_lock << true |
| 100 | + |
| 101 | + # Wait for both threads to complete |
| 102 | + thread.join |
| 103 | + install_thread.join |
| 104 | + |
| 105 | + second_install_out = install_output.pop |
| 106 | + |
| 107 | + expect(the_bundle).to include_gems "myrack 1.0.0" |
| 108 | + # The second install should have refreshed its cache after acquiring |
| 109 | + # the lock and seen that myrack was already installed |
| 110 | + expect(second_install_out).to include("Using myrack") |
| 111 | + end |
56 | 112 | end |
57 | 113 | end |
0 commit comments