Tests are failing when using multiple blueprints
I have an API with a lot of component. Each component has its own blueprint file and its own dredd config file. It's working perfectly.
My idea is to run all those separated tests at one by including all blueprints in one file. Unfortunately it does not work. Most of the tests are failing because of my
I have a bunch of hook files which are loading data in the database for each test. My errors are all related to the database not being populated.
The following configurations are not working:
...
blueprint: src/doc/bp*.apib
...
...
blueprint:
- src/doc/bp*.apib
...
...
blueprint:
- src/doc/bp1.apib
- src/doc/bp2.apib
...
The following configuration are working:
...
blueprint:
- src/doc/bp1.apib
...
...
blueprint: src/doc/bp1.apib
...
Am I missing something? Is this related to dredd or to https://github.com/ddelnano/dredd-hooks-php?
@aledeg I am thinking this is probably a dredd issue. I am not exactly sure how dredd treats multiple blueprint files but in order for that to work dredd would need to execute all transactions for a given blueprint file together (and not merge them) and also shutdown and restart a new hook server for each blueprint file.
Took a look into this some more and I don't think dredd supports wildcards for the blueprint config field. Someone that contributes to dredd would know more but from what I saw doesn't seem like it is supported.
I am not sure what happens under the hood. But when I provide multiple blueprint files, with wildcards or not, I have the same result. The blueprints files are loaded since all my actions are tested. The problem is that it looks like the code in the hooks are not executed since I do not have data in my database.
I think there are some tests to address this, but not very thorough in means of corner cases:
- https://github.com/apiaryio/dredd/blob/0b1721a889eb420b39b7ec68dbaf46b808f5b574/test/integration/cli/cli-test.coffee#L836
- https://github.com/apiaryio/dredd/blob/0b1721a889eb420b39b7ec68dbaf46b808f5b574/test/unit/dredd-test.coffee#L110
- https://github.com/apiaryio/dredd/blob/22c029382332520f07ee6c274bf117bc95d889bd/test/integration/cli/api-description-cli-test.coffee#L60
Would anyone be interested to contribute at least failing tests reproducing the issue?
The blueprints files are loaded since all my actions are tested. The problem is that it looks like the code in the hooks are not executed since I do not have data in my database.
So loading blueprints by glob pattern works well? But loading hooks by glob pattern may not work? I think we need to isolate the issue a bit first.
AFAIK Dredd's behavior is to load all given blueprints and all given hook files and test them. There is no blueprint/hookfile pairing involved and no concatenation. Blueprints are parsed separately and transactions from each of them are put together into a single list, then executed. Hooks are loaded and executed accordingly according to matching transaction names.
In my configuration, I am trying both glob pattern on blueprints and hooks. I made a test where I have one blueprint and many hooks (either with glob pattern or full path) and it works fine. I made a test where I have multiple blueprints and multiple hooks and it fails. But it has nothing with pairing. I am thinking that none of the hooks are executed in that configuration.
Would anyone be interested to contribute at least failing tests reproducing the issue?
Do you mean an integration test like the one you linked?
Do you mean an integration test like the one you linked?
Exactly, that would help tremendously!
I'll try, I've never used CoffeeScript. Any recommendation?
Regarding CoffeeScript, I can recommend to look at http://coffeescript.org/ to check at least the basics of the syntax (more advanced: https://arcturo.github.io/library/coffeescript/).
Regarding tests, I think the easiest way would be to add new test which would be the same as this one, but would load also blueprints by glob pattern.
To develop, check out the Contributing Guidelines. There are many pointers on how to develop Dredd. I'd also welcome feedback on the document - what can be improved etc.
@honzajavorek after some fighting, I think I have a valid failing test. I hope it helps !
@aledeg Awesome, thanks! :+1:
+1
+1
@vitkoczi @Zoltamcsak @matthiasKaeser We understand this is a wanted bug fix, but next time please use GitHub Reactions to express your feelings. Spamming a particular issue by +1 comments doesn't help anyone.
@honzajavorek sorry about the spamming, I wasn't aware of the (well hidden) github reactions. Thx for letting me know.
Hello @vitkoczi @Zoltamcsak @matthiasKaeser,
I am not able to reproduce the issue using [email protected]. I tested it with:
dredd.yml
dry-run: null
hookfiles:
- ./test/fixtures/glob1_hook.js
- ./test/fixtures/glob2_hook.js
language: nodejs
sandbox: false
server: node ./server.js
server-wait: 3
init: false
custom: {}
names: false
only: []
reporter: []
output: []
header: []
sorted: false
user: null
inline-errors: false
details: false
method: []
color: true
level: info
timestamp: false
silent: false
path: []
hooks-worker-timeout: 5000
hooks-worker-connect-timeout: 1500
hooks-worker-connect-retry: 500
hooks-worker-after-connect-wait: 100
hooks-worker-term-timeout: 5000
hooks-worker-term-retry: 500
hooks-worker-handler-host: 127.0.0.1
hooks-worker-handler-port: 61321
config: ./dredd.yml
blueprint:
- ./test/fixtures/glob1.apib
- ./test/fixtures/glob2.apib
endpoint: 'http://127.0.0.1:3000'
Note: Using blueprint: ./test/fixtures/glob* or
blueprint:
- ./test/fixtures/glob1.apib
- ./test/fixtures/glob2.apib
also works. (Same for hookfiles.)
./server.js
const express = require('express');
const app = express();
app.set('port', (process.env.PORT || 3000));
app.get('/machines', (req, res) => {
res.setHeader('Content-Type', 'application/json');
res.status(200).json([{
name: 'willy',
type: 'bulldozer'
}]);
});
app.get('/planes', (req, res) => {
res.setHeader('Content-Type', 'application/json');
res.status(200).json([{
name: 'El Chupacabra',
type: 'Gee Bee Model R'
}]);
});
app.listen(app.get('port'), () => {
console.log('Server started: http://localhost:' + app.get('port') + '/');
});
./test/fixtures/glob1_hook.js
const hooks = require('hooks');
hooks.before('Machines > Machines collection > Get Machines', function (transaction, done) {
transaction.request.headers['header'] = '123-machine';
return done();
});
./test/fixtures/glob2_hook.js
const hooks = require('hooks');
hooks.before('Planes > Planes collection > Get Planes', function(transaction, done) {
transaction.request.headers['header'] = '123-plane';
return done();
});
./test/fixtures/glob1.apib
FORMAT: 1A
# Machines API
# Group Machines
# Machines collection [/machines]
## Get Machines [GET]
- Response 200 (application/json; charset=utf-8)
[
{
"type": "bulldozer",
"name": "willy"
}
]
./test/fixtures/glob2.apib
FORMAT: 1A
# Planes API
# Group Planes
# Planes collection [/planes]
## Get Planes [GET]
- Response 200 (application/json; charset=utf-8)
[
{
"type": "Gee Bee Model R",
"name": "El Chupacabra"
}
]
Result
Michals-MacBook-Pro:dredd michalholasek$ ./bin/dredd
info: Configuration './dredd.yml' found, ignoring other arguments.
info: Starting backend server process with command: node ./server.js
info: Waiting 3 seconds for backend server process to start /dredd/test/fixtures/glob2_hook.js
Server started: http://localhost:3000/
info: Beginning Dredd testing...
info: Found Hookfiles: 0=/Users/michalholasek/Repository/dredd/test/fixtures/glob1_hook.js, 1=/Users/michalholasek/Repository
/dredd/test/fixtures/glob2_hook.js
pass: GET (200) /planes duration: 53ms
pass: GET (200) /machines duration: 24ms
complete: 2 passing, 0 failing, 0 errors, 0 skipped, 2 total
complete: Tests took 95ms
info: Backend server process exited
Would you mind sharing dredd version, dredd.yml and API Description / hookfile fixtures you are using? Thank you.
My hunch would be this has been silently resolved by https://github.com/apiaryio/dredd/pull/803 in the past, so it's not possible to reproduce the problem anymore. However, @vitkoczi @Zoltamcsak, and @matthiasKaeser were adding +1 just recently. Folks, what Dredd version are you using? Could you help us to reproduce the problem? Otherwise we'll have to close this.