Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Add Hypertest scenarios #104

Merged
merged 21 commits into from
Dec 19, 2019
Merged

Conversation

thewilkybarkid
Copy link
Contributor

Adds functional tests of the Hydra API.

@thewilkybarkid thewilkybarkid added the ⚙️ CI Changes to the continuous integration configuration files and scripts label Dec 10, 2019
.github/hypertest.sh Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
@thewilkybarkid
Copy link
Contributor Author

Currently seeing

Failed to dereference http://localhost:8080/ FetchError: request to http://localhost:8080/ failed, reason: socket hang up

in CI, and locally it just hangs (and can't SIGTERM out).

@thewilkybarkid
Copy link
Contributor Author

Works outside of Docker.

@thewilkybarkid
Copy link
Contributor Author

@giorgiosironi I'm seeing different behaviour on MacOS to GitHub Actions (neither actually working though). What do you see?

@giorgiosironi
Copy link
Member

My output: failure, but the networking seems to work.

------
   Compiling test scenarios
   Directory used: /tests
   Using temp directory for compiled output: /tmp/d-20191111-13-3523ti.z3n1i
------

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$2 (file:/hydra-validator/node_modules/@hydrofoil/hypertest/jdeploy-bundle/app.hypermedia.testing.dsl.cli-1.0.0-SNAPSHOT-shaded.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$2
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Compiling article-list.hydra
Done!

------
   Running scenario article-list
------

2019-12-11T09:42:51.143Z INFO      Analysis started...
2019-12-11T09:42:51.221Z INFO      Fetched resource http://localhost:8080/
2019-12-11T09:42:51.222Z SUCCESS   Found expected property http://schema.org/name
2019-12-11T09:42:51.223Z WARNING   Stepping into link http://www.w3.org/ns/hydra/core#collection Resources found but http://www.w3.org/ns/hydra/core#collection is not a SupportedProperty of hydra:Link type.
2019-12-11T09:42:51.263Z INFO      -- Fetched resource http://localhost:8080/articles
2019-12-11T09:42:51.264Z SUCCESS   -- Found expected property http://www.w3.org/ns/hydra/core#title
2019-12-11T09:42:51.264Z INFO      -- Stepping into property http://www.w3.org/ns/hydra/core#manages
2019-12-11T09:42:51.264Z SUCCESS   ---- Found expected property http://www.w3.org/ns/hydra/core#property
2019-12-11T09:42:51.264Z SUCCESS   ---- Found expected property http://www.w3.org/ns/hydra/core#object
2019-12-11T09:42:51.264Z SUCCESS   -- Found expected property http://www.w3.org/ns/hydra/core#totalItems
2019-12-11T09:42:51.264Z INFO      -- Stepping into members of array http://www.w3.org/ns/hydra/core#member
2019-12-11T09:42:51.264Z FAILURE   Executed 10 out of 12 steps. Strict mode requires that all steps are executed
2019-12-11T09:42:51.265Z FAILURE   Analysis complete with errors Success: 5, Warnings: 1, Failures: 1

------
   Summary
------

0/1 scenarios succeeded.

------
   Failed scenarios
------

  - article-list

@giorgiosironi
Copy link
Member

I suspected some issue with the Docker containers accessing the host network. Introducing a smoke test for that changed the result, so there may be some race conditions in the bootstrap.

@thewilkybarkid
Copy link
Contributor Author

Seems to be working now (ie Hypertest is running; both locally and on Actions). Not sure why.

@giorgiosironi
Copy link
Member

Hypothesis is the smoke test stalls the process long enough for everything to be wired up and localhost:8080 to lead to the right place. But still the checks are failing?

@thewilkybarkid
Copy link
Contributor Author

Seems fine without.

@thewilkybarkid
Copy link
Contributor Author

Warning is #49.

@thewilkybarkid
Copy link
Contributor Author

Main Hypertest failure relates to

With Property hydra:member {
Expect Type schema:Article
Expect Property schema:name
}
but there are none and strict mode is enabled. Adding the operation should fix it.

@giorgiosironi
Copy link
Member

Seems fine without.

Could have been a unlucky original run, not sure if it reproduced easily.

@giorgiosironi
Copy link
Member

I'll disappear from here until ready for review 👍

@thewilkybarkid
Copy link
Contributor Author

thewilkybarkid commented Dec 11, 2019

Things I've learnt:

  • 204 No Content isn't suitable following a POST as there's no links to follow (this was only temporary anyway, as current the articles aren't separate resources)
  • Named operations are good. I've introduced Schema.org action types, but proper identified actions is probably better (eg http://libero.pub/article-store/add-article).
  • It doesn't look feasible to do tests like 'add an article then it should appear in the article list', but think that's ok (and handled by the other types of tests).
  • Probably don't want to check most properties are present (currently check for the existence of 'hydra:property' in 'hydra:manages' on a 'hydra:Collection'), instead rely on the other tests.

@thewilkybarkid
Copy link
Contributor Author

Still got one warning related to the add article operation: Could not determine the resource representation. Not sure what it's referring too.

Also see No processor found for media type text/plain; charset=utf-8 in the logs.

@tpluscode
Copy link

Could not determine the resource representation

It means that the resource graph did not contain the resource identifier by the dereferenced URI.

For example, you request http://example.app/resource-one?q=foo but got

<http://example.app/resource-two> schema:name "I'm not resource one" ;
<http://example.app/resource-one> schema:name "I am similar but not exactly the same"

The client alcaeus looks for the /resource-one?q=foo resource with exact string comparison. It will not find the one without query params, hence the warning.

Please refer to Root resource page in alcaeus' docs for some ways it tries to figure out the right resource to return from the graph

I might have rephrase this message. Ideas welcome.

@thewilkybarkid
Copy link
Contributor Author

It means that the resource graph did not contain the resource identifier by the dereferenced URI.

Seems to be the 201 Created response to the POST, which doesn't contain a body. (The docs do define hydra:returns as owl:nothing.)

@tpluscode
Copy link

The docs notwithstanding, I think I could skip this warning if the body is indeed empty. Or at least in empty 204 and 201 responses.

@thewilkybarkid
Copy link
Contributor Author

thewilkybarkid commented Dec 12, 2019

Also see No processor found for media type text/plain; charset=utf-8 in the logs.

Just noticed the Generic Hydra Application emits the same following a POST with no body.

Edit: Just seen that Koa is returning 'Created' as the body, rather than no body at all...

@thewilkybarkid
Copy link
Contributor Author

Will mark as ready when a new version of hydrofoil/hypertest is tagged.

@thewilkybarkid thewilkybarkid marked this pull request as ready for review December 18, 2019 10:43
@thewilkybarkid thewilkybarkid requested a review from a team as a code owner December 18, 2019 10:43
@thewilkybarkid
Copy link
Contributor Author

Might as well review now, but won't merged until a released is tagged. /cc @tpluscode

@tpluscode
Copy link

Anything still missing/not working for you? If not they let me tag the current state

@thewilkybarkid
Copy link
Contributor Author

Works fine, we can carry on using --init to get round hypermedia-app/hypertest-docker#2.

@tpluscode
Copy link

Tagged as 0.4.0. Docker hub is going to build it soon

@thewilkybarkid thewilkybarkid merged commit 8ca4127 into libero:master Dec 19, 2019
@thewilkybarkid thewilkybarkid deleted the hypertest branch December 19, 2019 16:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
⚙️ CI Changes to the continuous integration configuration files and scripts
Projects
None yet
3 participants