Skip to content

Fix learn-ocaml-client regression after PR #320 #397

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

Merged
merged 9 commits into from
Jun 24, 2021

Conversation

erikmd
Copy link
Member

@erikmd erikmd commented Jun 18, 2021

With @LouisAyroles and @Fixiss, we noticed that there were some (unexpected) incompatibility between learn-ocaml-client (say, from master) and the latest release of learn-ocaml (0.12).

Here a minimal working example to reproduce the bug:

cd .../learn-ocaml
docker run --name=locaml -d -it -p 8080:8080 -v "$PWD/demo-repository:/repository" ocamlsf/learn-ocaml:0.12
TOKEN=$(docker logs locaml | grep -e 'Initial teacher token created:' | sed -e 's/^.*: //')
# then
git checkout master
opam install . --deps-only --locked -y
opam install -y opam-installer.$(opam config var opam-version)
eval $(opam env)
make
make opaminstall
learn-ocaml-client init -s http://localhost:8080 -t "$TOKEN"
touch demo.ml
learn-ocaml-client grade demo.ml

then we were getting:

Fatal error: exception Json_encoding.Cannot_destruct(_)
Called from unknown location
Called from unknown location
Called from unknown location
Called from unknown location
Called from unknown location
Called from unknown location
Called from unknown location

Thanks to git bisect and further explorations, it appears the issue was just introduced in PR #320.

This new PR attempts to fix this issue (very important to have some smooth experience with learn-ocaml-client and learn-ocaml.el), and I'll proceed in a TDD-like manner (extended the GHA CI test-suite within this PR).

@erikmd erikmd force-pushed the fix-client-regression-from-ghpr320 branch 3 times, most recently from dd202a7 to b9109ac Compare June 18, 2021 19:42
erikmd added 2 commits June 18, 2021 22:41
* Adapt ./tests/runtests.sh so it recognizes USE_CLIENT_IMAGE=true

* Update .github/workflows/build-and-test.yml accordingly
  so learn-ocaml-client runs against each ${{ matrix.server_image }}
This ensures learn-ocaml-client.master is still able to query a server
version learn-ocaml.0.12.

Minimal working example:
  cd .../learn-ocaml
  docker run --name=locaml -d -it -p 8080:8080 -v "$PWD/demo-repository:/repository" ocamlsf/learn-ocaml:0.12
  TOKEN=$(docker logs locaml | grep -e 'Initial teacher token created:' | sed -e 's/^.*: //')
  # then
  git checkout 42d8127
  opam install . --deps-only --locked -y
  opam install -y opam-installer.$(opam config var opam-version)
  eval $(opam env)
  make
  make opaminstall
  learn-ocaml-client init -s http://localhost:8080 -t "$TOKEN"
  touch demo.ml
  learn-ocaml-client grade demo.ml

Output before the fix:
  Fatal error: exception Json_encoding.Cannot_destruct(_)
  Called from unknown location
  Called from unknown location
  Called from unknown location
  Called from unknown location
  Called from unknown location
  Called from unknown location
  Called from unknown location
@erikmd erikmd force-pushed the fix-client-regression-from-ghpr320 branch from ebbfc3c to c00a3ab Compare June 18, 2021 20:41
@erikmd
Copy link
Member Author

erikmd commented Jun 18, 2021

This PR is now ready, but before merging I'd like to have some confirmation by @yurug that the fix-commit cd9291e does not have unforeseen side-effects, on existing exercises you may have prepared, and that would specifically rely on the depend.txt feature.

Summary of the PR

  • The first commit exhibits the issue, as displayed in this GHA log:
    Run cd tests && bash -c ./runtests.sh
    Running tests with BOTH images (learn-ocaml, learn-ocaml-client)
    ---> Entering ./test1:
    Configuration written to /home/learn-ocaml/.config/learnocaml/client.json.
    NOT OK: ./test1/demo2.ml
    Reading solution...
    Fetching exercise data from server...
    Fatal error: exception Json_encoding.Cannot_destruct(_)
    Called from unknown location
    Called from unknown location
    Called from unknown location
    Called from unknown location
    Called from unknown location
    Called from unknown location
    Called from unknown location
    Error: Process completed with exit code 1.
    
  • The second commit fixes the compatibility issue, as displayed in this GHA log:
    Run cd tests && bash -c ./runtests.sh
    Running tests with BOTH images (learn-ocaml, learn-ocaml-client)
    ---> Entering ./test1:
    Configuration written to /home/learn-ocaml/.config/learnocaml/client.json.
    OK: ./test1/demo2.ml
    OK: ./test1/bad_plus_2.ml
    OK: ./test1/demo.ml
    OK: ./test1/bad_plus.ml
    find: ‘./corpuses’: No such file or directory
    
    where (learn-ocaml, learn-ocaml-client) are specifically chosen of version (HEAD, 0.12):
    Run docker inspect -f '{{json .Config.Labels}}' learn-ocaml-client learn-ocaml | jq
    {
      "org.opencontainers.image.description": "learn-ocaml command-line client",
      "org.opencontainers.image.title": "learn-ocaml-client",
      "org.opencontainers.image.url": "https://ocaml-sf.org/",
      "org.opencontainers.image.vendor": "The OCaml Software Foundation"
    }
    {
      "org.label-schema.build-date": "2020-02-19T20:59:22Z",
      "org.label-schema.description": "learn-ocaml app manager",
      "org.label-schema.name": "learn-ocaml",
      "org.label-schema.schema-version": "1.0",
      "org.label-schema.url": "https://ocaml-sf.org/",
      "org.label-schema.vcs-ref": "c54d3bb",
      "org.label-schema.vcs-url": "https://github.com/ocaml-sf/learn-ocaml",
      "org.label-schema.vendor": "The OCaml Software Foundation",
      "org.label-schema.version": "0.12"
    }
    

(Note that the GHA logs are not archived indefinitely, hence the copy-and-paste in the above snippets.)

@erikmd erikmd requested a review from yurug June 18, 2021 21:06
@erikmd
Copy link
Member Author

erikmd commented Jun 23, 2021

The last-but-one CI run failed because it seems the token is not yet created at the time the server listens to the TCP port…

I've pushed a slightly different way to get this token but I believe it might still fail.

FTR:

id=$(docker run --rm -d -it -p 8080:8080 -v "$PWD:/repository" ocamlsf/learn-ocaml:0.12)
docker logs -t $id
2021-06-23T12:52:53.899527427Z Learnocaml v.0.12 running.
2021-06-23T12:52:53.899557308Z Updating app at ./www
2021-06-23T12:52:53.943510782Z Learnocaml server v.0.12 starting on port 8080
2021-06-23T12:52:53.944241170Z Initial teacher token created: X-AYC-4FE-R1O-ZLD

so @yurug, wouldn't you mind if I rather write
./wait-for-it.sh localhost:8080 -s -t 10 -- sleep 1s?

this shouldn't be fragile (as unrelated to the build time of the repo): this extra second should just be required to account for the difference time _:53.944241170Z - _:53.943510782Z

@yurug
Copy link
Collaborator

yurug commented Jun 23, 2021

so @yurug, wouldn't you mind if I rather write
./wait-for-it.sh localhost:8080 -s -t 10 -- sleep 1s?

Fine for me!

@erikmd
Copy link
Member Author

erikmd commented Jun 23, 2021

Thanks @yurug, actually wait-for-it.sh was not enough, so I needed to implement a small curl-based custom function.

Now the code related to your initial comment reads:

if ! wait_for_it "http://localhost:8080/version" "$build_timeout" sleep 1s  # ...

I thoroughly improved the bash script along the way, and did several tests locally: everything looks fine… so let's wait for the CI :)

erikmd added 5 commits June 23, 2021 23:27
* The standard wait_for_it.sh script was not enough:

  very quickly, the server acknowledges wait_for_it.sh

  but "curl http://localhost:8080/version" fails with:

    curl: (56) Recv failure: Connection reset by peer
@erikmd erikmd force-pushed the fix-client-regression-from-ghpr320 branch from d62aa2c to 674c2f2 Compare June 23, 2021 21:27
@erikmd erikmd force-pushed the fix-client-regression-from-ghpr320 branch from 674c2f2 to 8e06dd7 Compare June 23, 2021 21:51
@erikmd
Copy link
Member Author

erikmd commented Jun 23, 2021

OK so if this very last CI run is OK ✔️, you'll be able to merge this PR anytime this Thursday, @yurug :)

@yurug yurug merged commit 5b16c92 into ocaml-sf:master Jun 24, 2021
@yurug
Copy link
Collaborator

yurug commented Jun 24, 2021

Thank you @erikmd!

@erikmd erikmd deleted the fix-client-regression-from-ghpr320 branch June 24, 2021 06:28
@erikmd
Copy link
Member Author

erikmd commented Jun 24, 2021

Hi @yurug, small remark: it happens there are 3 PR merging strategies in GitHub (Merge, Merge/Squash, Merge/Rebase).

But Merge/Rebase has two drawbacks:

  • there is no mention anywhere of the PR number in the resulting commits;
  • and the resulting commits are not GPG-signed…

While Merge and Merge/Squash are very fine (Merge/Squash being especially fine if the PR contains only one commit).

So, maybe for upcoming PRs we should only use Merge or Merge/Squash 😅

@yurug
Copy link
Collaborator

yurug commented Sep 30, 2021

OK. We indeed need to follow one merging strategy. Merge/Rebase has indeed these two drawbacks but also has advantages (more readable linear history is sometimes very useful). Anyway, your arguments are valid and I will use Merge and Merge/Squash in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants