Skip to content

Commit

Permalink
reftest: Add a test for installed packages cache update after an acti…
Browse files Browse the repository at this point in the history
…on failure

It highlights a package mistakenly marked as to be reinstalled

Co-authored-by: Raja Boujbel <raja.boujbel@ocamlpro.com>
  • Loading branch information
kit-ty-kate and rjbou committed Oct 11, 2024
1 parent 755e69e commit a49bff9
Show file tree
Hide file tree
Showing 3 changed files with 350 additions and 0 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ users)
* Move pin test to pin-legacy [#6135 @rjbou]
* More exhaustive test for pin command: test different behaviour and cli options [#6135 @rjbou]
* pin: add a test for erroneous first fetch done as local path on local VCS pinned packages [#6221 @rjbou]
* Add cache test for installed packages cache update after an action failure [#6213 @kit-ty-kate @rjbou]

### Engine
* Update print file function [#6233 @rjbou]
Expand Down
328 changes: 328 additions & 0 deletions tests/reftests/cache.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
N0REP0
### :: Installed Cache update on action failure
### : Origin
### : upgrades from 2.2 to 2.3 can trigger issues where a repository forgot to
### : add the missing extra-files field, opam tells the user they should
### : upgrade as the opam file changed (as extra-files was added automatically)
### : then the build fails and upon fixing the error opam still says the
### : package is to be rebuilt because the previous version of the opam file
### : was stored in the install cache
### : The bug is seen on specific case : a package is already installed, and
### : its update that doesn't remove it (fetch or build failure) update the
### : cache with the wrong opam file, the one from repo state.
### opam switch create action-failure --empty
### OPAMYES=1
### <pkg:always-here.1>
opam-version: "2.0"
### opam install always-here
The following actions will be performed:
=== install 1 package
- install always-here 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed always-here.1
Done.
### ::: Build
### <pkg:upgrade.1>
opam-version: "2.0"
build: "true"
### opam install upgrade.1
The following actions will be performed:
=== install 1 package
- install upgrade 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed upgrade.1
Done.
### <pkg:upgrade.1>
opam-version: "2.0"
build: "false"
### opam upgrade
The following actions will be performed:
=== recompile 1 package
- recompile upgrade 1 [upstream or system changes]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] The compilation of upgrade.1 failed at "false".




<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
+- The following actions failed
| - build upgrade 1
+-
- No changes have been performed
# Return code 31 #
### <pkg:upgrade.1>
opam-version: "2.0"
build: "true"
### opam show --raw upgrade.1
opam-version: "2.0"
name: "upgrade"
version: "1"
build: "true"
### cat ${BASEDIR}/OPAM/action-failure/.opam-switch/packages/upgrade.1/opam
opam-version: "2.0"
build: "true"
### opam-cache repo upgrade
=> default:upgrade.1 <=
opam-version: "2.0"
name: "upgrade"
version: "1"
build: "true"
### opam-cache installed action-failure
=> upgrade.1 <=
opam-version: "2.0"
name: "upgrade"
version: "1"
build: "false"
=> always-here.1 <=
opam-version: "2.0"
name: "always-here"
version: "1"
### opam upgrade
The following actions will be performed:
=== recompile 1 package
- recompile upgrade 1 [upstream or system changes]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> removed upgrade.1
-> installed upgrade.1
Done.
### opam-cache installed action-failure
=> upgrade.1 <=
opam-version: "2.0"
name: "upgrade"
version: "1"
build: "true"
=> always-here.1 <=
opam-version: "2.0"
name: "always-here"
version: "1"
### ::: Install
### opam remove upgrade
The following actions will be performed:
=== remove 1 package
- remove upgrade 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> removed upgrade.1
Done.
### <pkg:upgrade.1>
opam-version: "2.0"
install: "true"
### opam install upgrade
The following actions will be performed:
=== install 1 package
- install upgrade 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed upgrade.1
Done.
### opam-cache installed action-failure
=> upgrade.1 <=
opam-version: "2.0"
name: "upgrade"
version: "1"
install: "true"
=> always-here.1 <=
opam-version: "2.0"
name: "always-here"
version: "1"
### <pkg:upgrade.1>
opam-version: "2.0"
install: "false"
### opam install upgrade | grep -v import
The following actions will be performed:
=== recompile 1 package
- recompile upgrade 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> removed upgrade.1
[ERROR] The installation of upgrade failed at "false".




<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
+- The following actions failed
| - install upgrade 1
+-
+- The following changes have been performed
| - remove upgrade 1
+-

The former state can be restored with:
Or you can retry to install your package selection with:
${OPAM} install --restore
# Return code 31 #
### test -f ${BASEDIR}/OPAM/action-failure/.opam-switch/packages/upgrade.1/opam
# Return code 1 #
### opam-cache installed action-failure
No cache
### ::: Remove standalone
### <pkg:upgrade.1>
opam-version: "2.0"
remove: "false"
### opam install upgrade
The following actions will be performed:
=== install 1 package
- install upgrade 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed upgrade.1
Done.
### opam-cache installed action-failure
=> upgrade.1 <=
opam-version: "2.0"
name: "upgrade"
version: "1"
remove: "false"
=> always-here.1 <=
opam-version: "2.0"
name: "always-here"
version: "1"
### opam remove upgrade | grep -v " #" | '^\[WARNING] package uninstall script failed at .*' -> '[WARNING] package uninstall script failed'
The following actions will be performed:
=== remove 1 package
- remove upgrade 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[WARNING] package uninstall script failed

Done.
### test -f ${BASEDIR}/OPAM/action-failure/.opam-switch/packages/upgrade.1/opam
# Return code 1 #
### opam-cache installed action-failure
No cache
### ::: Remove on reinstall
### <pkg:upgrade.1>
opam-version: "2.0"
### opam install upgrade
The following actions will be performed:
=== install 1 package
- install upgrade 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed upgrade.1
Done.
### opam-cache installed action-failure
=> upgrade.1 <=
opam-version: "2.0"
name: "upgrade"
version: "1"
=> always-here.1 <=
opam-version: "2.0"
name: "always-here"
version: "1"
### <pkg:upgrade.1>
opam-version: "2.0"
remove: "false"
### opam upgrade
The following actions will be performed:
=== recompile 1 package
- recompile upgrade 1 [upstream or system changes]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> removed upgrade.1
-> installed upgrade.1
Done.
### cat ${BASEDIR}/OPAM/action-failure/.opam-switch/packages/upgrade.1/opam
opam-version: "2.0"
remove: "false"
### opam-cache installed action-failure
=> upgrade.1 <=
opam-version: "2.0"
name: "upgrade"
version: "1"
remove: "false"
=> always-here.1 <=
opam-version: "2.0"
name: "always-here"
version: "1"
### <pkg:upgrade.1>
opam-version: "2.0"
### opam upgrade | grep -v " #" | '^\[WARNING] package uninstall script failed at .*' -> '[WARNING] package uninstall script failed'
The following actions will be performed:
=== recompile 1 package
- recompile upgrade 1 [upstream or system changes]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[WARNING] package uninstall script failed

-> installed upgrade.1
Done.
### cat ${BASEDIR}/OPAM/action-failure/.opam-switch/packages/upgrade.1/opam
opam-version: "2.0"
### opam-cache installed action-failure
=> upgrade.1 <=
opam-version: "2.0"
name: "upgrade"
version: "1"
=> always-here.1 <=
opam-version: "2.0"
name: "always-here"
version: "1"
### ::: Fetch
### opam remove upgrade
The following actions will be performed:
=== remove 1 package
- remove upgrade 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> removed upgrade.1
Done.
### <pkg:upgrade.1>
opam-version: "2.0"
### opam install upgrade
The following actions will be performed:
=== install 1 package
- install upgrade 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed upgrade.1
Done.
### opam-cache installed action-failure
=> upgrade.1 <=
opam-version: "2.0"
name: "upgrade"
version: "1"
=> always-here.1 <=
opam-version: "2.0"
name: "always-here"
version: "1"
### <pkg:upgrade.1>
opam-version: "2.0"
url { src:"/inexistent/path" }
### opam install upgrade | '"C:/' -> '"/' | ' C:/' -> ' /'
The following actions will be performed:
=== recompile 1 package
- recompile upgrade 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] Failed to get sources of upgrade.1: /inexistent/path

OpamSolution.Fetch_fail("/inexistent/path")


<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
+- The following actions failed
| - fetch upgrade 1
+-
- No changes have been performed
# Return code 40 #
### cat ${BASEDIR}/OPAM/action-failure/.opam-switch/packages/upgrade.1/opam
opam-version: "2.0"
### opam-cache installed action-failure
=> upgrade.1 <=
opam-version: "2.0"
name: "upgrade"
version: "1"
url {
src: "file:///inexistent/path"
}
=> always-here.1 <=
opam-version: "2.0"
name: "always-here"
version: "1"
21 changes: 21 additions & 0 deletions tests/reftests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,27 @@
%{targets}
(run ./run.exe %{exe:../../src/client/opamMain.exe.exe} %{dep:best-effort.test} %{read-lines:testing-env}))))

(rule
(alias reftest-cache)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
(action
(diff cache.test cache.out)))

(alias
(name reftest)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
(deps (alias reftest-cache)))

(rule
(targets cache.out)
(deps root-N0REP0)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
(package opam)
(action
(with-stdout-to
%{targets}
(run ./run.exe %{exe:../../src/client/opamMain.exe.exe} %{dep:cache.test} %{read-lines:testing-env}))))

(rule
(alias reftest-clean)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
Expand Down

0 comments on commit a49bff9

Please sign in to comment.