Skip to content

Commit

Permalink
Fail doc tests when any shard fails
Browse files Browse the repository at this point in the history
ES only sends a non-200 response all shards fail but we should
fail the tests generated by docs if any of them fail.

Depending on the outcome of elastic#18978 this might be a temporary
workaround.
  • Loading branch information
nik9000 committed Jun 20, 2016
1 parent 9196ff2 commit 6569d35
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
current.println(setup)
}

body(test)
body(test, false)
}

private void response(Snippet response) {
Expand All @@ -136,7 +136,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
}

void emitDo(String method, String pathAndQuery,
String body, String catchPart) {
String body, String catchPart, boolean inSetup) {
def (String path, String query) = pathAndQuery.tokenize('?')
current.println(" - do:")
if (catchPart != null) {
Expand All @@ -160,6 +160,19 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
current.println(" body: |")
body.eachLine { current.println(" $it") }
}
/* Catch any shard failures. These only cause a non-200 response if
* no shard succeeds. But we need to fail the tests on all of these
* because they mean invalid syntax or broken queries or something
* else that we don't want to teach people to do. The REST test
* framework doesn't allow us to has assertions in the setup
* section so we have to skip it there. We also have to skip _cat
* actions because they don't return json so we can't is_false
* them. That is ok because they don't have this
* partial-success-is-success thing.
*/
if (false == inSetup && false == path.startsWith('_cat')) {
current.println(" - is_false: _shards.failures")
}
}

private void setup(Snippet setup) {
Expand All @@ -169,7 +182,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
setupCurrent(setup)
current.println('---')
current.println("setup:")
body(setup)
body(setup, true)
// always wait for yellow before anything is executed
current.println(
" - do:\n" +
Expand All @@ -179,7 +192,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
" wait_for_status: \"yellow\"")
}

private void body(Snippet snippet) {
private void body(Snippet snippet, boolean inSetup) {
parse("$snippet", snippet.contents, SYNTAX) { matcher, last ->
if (matcher.group("comment") != null) {
// Comment
Expand All @@ -193,7 +206,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
// Leading '/'s break the generated paths
pathAndQuery = pathAndQuery.substring(1)
}
emitDo(method, pathAndQuery, body, catchPart)
emitDo(method, pathAndQuery, body, catchPart, inSetup)
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/modules/scripting/painless.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ GET hockey/_search
"order": "asc",
"script": {
"lang": "painless",
"inline": "doc['first'].value + ' ' + doc['last'].value"
"inline": "doc['first.keyword'].value + ' ' + doc['last.keyword'].value"
}
}
}
Expand Down

0 comments on commit 6569d35

Please sign in to comment.