-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9140 from Leonidas-from-XIV/git-flock
fix(pkg): Add a lock around the revision store
- Loading branch information
Showing
6 changed files
with
211 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Testing whether the revision store locks properly. | ||
|
||
To start with we create a repository in with a `foo` package. | ||
|
||
$ . ./helpers.sh | ||
$ mkrepo | ||
$ mkpkg foo 1.0 <<EOF | ||
> EOF | ||
$ cd mock-opam-repository | ||
$ git init --quiet | ||
$ git add -A | ||
$ git commit --quiet -m "Initial commit" | ||
$ cd .. | ||
|
||
We set this repository as sole source for opam repositories. | ||
|
||
$ cat > dune-workspace <<EOF | ||
> (lang dune 3.10) | ||
> (repository | ||
> (name mock) | ||
> (source "git+file://$(pwd)/mock-opam-repository")) | ||
> (context | ||
> (default | ||
> (name default) | ||
> (repositories mock))) | ||
> EOF | ||
|
||
We set the project up to depend on `foo` | ||
|
||
$ cat > dune-project <<EOF | ||
> (lang dune 3.10) | ||
> | ||
> (package | ||
> (name bar) | ||
> (depends foo)) | ||
> EOF | ||
$ cat > dune <<EOF | ||
> EOF | ||
|
||
Creating a lock should thus work. | ||
|
||
$ mkdir dune-workspace-cache | ||
$ XDG_CACHE_HOME=$(pwd)/fake-xdg-cache dune pkg lock | ||
Solution for dune.lock: | ||
- foo.1.0 | ||
|
||
There should also be some kind of error message if getting the revision store | ||
lock fails (simulated here with a failing flock(2) call): | ||
|
||
$ XDG_CACHE_HOME=$(pwd)/dune-workspace-cache strace -e inject=flock:error=EBADFD -o /dev/null dune pkg lock | ||
Error: Failed to get a lock for the revision store at | ||
$TESTCASE_ROOT/dune-workspace-cache/dune/rev-store.lock: | ||
File descriptor in bad state | ||
[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
open Stdune | ||
open Fiber.O | ||
module Scheduler = Dune_engine.Scheduler | ||
module Process = Dune_engine.Process | ||
module Display = Dune_engine.Display | ||
module Rev_store = Dune_pkg.Rev_store | ||
module Vcs = Dune_vcs.Vcs | ||
|
||
let () = Dune_tests_common.init () | ||
|
||
let run thunk = | ||
let on_event _config _event = () in | ||
let config : Scheduler.Config.t = | ||
{ concurrency = 1 | ||
; stats = None | ||
; insignificant_changes = `Ignore | ||
; signal_watcher = `No | ||
; watch_exclusions = [] | ||
} | ||
in | ||
Scheduler.Run.go config ~on_event thunk | ||
;; | ||
|
||
let display = Display.Quiet | ||
let output_limit = Sys.max_string_length | ||
let make_stdout () = Process.Io.make_stdout ~output_on_success:Swallow ~output_limit | ||
let make_stderr () = Process.Io.make_stderr ~output_on_success:Swallow ~output_limit | ||
|
||
let create_repo_at dir = | ||
let stdout_to = make_stdout () in | ||
let stderr_to = make_stdout () in | ||
let git = | ||
let git = Lazy.force Vcs.git in | ||
Process.run ~dir ~display ~stdout_to ~stderr_to Process.Failure_mode.Strict git | ||
in | ||
Path.mkdir_p dir; | ||
let* () = git [ "init" ] in | ||
let entry_name = "entry" in | ||
let entry = Path.relative dir entry_name in | ||
Io.write_lines entry [ "just some content" ]; | ||
let* () = git [ "add"; entry_name ] in | ||
git [ "commit"; "-m 'Initial commit'" ] | ||
;; | ||
|
||
let%expect_test "adding remotes" = | ||
let cwd = Path.External.cwd () |> Path.external_ in | ||
let dir = Path.relative cwd "git-repo" in | ||
run (fun () -> | ||
let* rev_store = Rev_store.load_or_create ~dir in | ||
let remote_path = Path.relative cwd "git-remote" in | ||
let* () = create_repo_at remote_path in | ||
let source = Path.to_string remote_path in | ||
let* _remote = Rev_store.add_repo rev_store ~source in | ||
print_endline "Creating first remote succeeded"; | ||
let* _remote' = Rev_store.add_repo rev_store ~source in | ||
print_endline "Adding same remote succeeded"; | ||
Fiber.return ()); | ||
[%expect {| | ||
Creating first remote succeeded | ||
Adding same remote succeeded | ||
|}] | ||
;; |