Skip to content

Painless: more testing for script_stack#24168

Merged
nik9000 merged 6 commits intoelastic:masterfrom
nik9000:painless_npes
Apr 19, 2017
Merged

Painless: more testing for script_stack#24168
nik9000 merged 6 commits intoelastic:masterfrom
nik9000:painless_npes

Conversation

@nik9000
Copy link
Copy Markdown
Member

@nik9000 nik9000 commented Apr 18, 2017

script_stack is super useful when debugging Painless scripts
because it skips all the "weird" stuff involved that obfuscates
where the actual error is. It skips Painless's internals and
call site bootstrapping.

It works fine, but it didn't have many tests. This converts a
test that we had for line numbers into a test for the
script_stack. The line numbers test was an indirect test
for script_stack.

`script_stack` is super useful when debugging Painless scripts
because it skips all the "weird" stuff involved that obfuscates
where the actual error is. It skips Painless's internals and
call site bootstrapping.

It works fine, but it didn't have many tests. This converts a
test that we had for line numbers into a test for the
`script_stack`. The line numbers test was an indirect test
for `script_stack`.
@nik9000 nik9000 added :Plugin Lang Painless >test Issues or PRs that are addressing/adding tests v5.5.0 v6.0.0-alpha1 labels Apr 18, 2017
@nik9000 nik9000 requested a review from jdconrad April 18, 2017 22:23
runnable.run();
} catch (Throwable e) {
if (e instanceof ScriptException) {
boolean hasEmptyScriptStack = ((ScriptException) e).getScriptStack().isEmpty();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally hunting down a case where we weren't producing the stack. I never found it but I figure something like this is nice to have around anyway.

} catch (Throwable e) {
if (e instanceof ScriptException) {
boolean hasEmptyScriptStack = ((ScriptException) e).getScriptStack().isEmpty();
if (shouldHaveScriptStack) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would read cleaner as:

if (shouldHaveScriptStack && hasEmptyScripStack) {
  ...
} else if (shouldHaveScriptStack == false && hasEmptyScriptStack == false) {
  ...
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do it that way, sure.

exec("Double.parseDouble(params['missing'])");
});
// null deref at x.isEmpty(), the '.' is offset 30 (+1)
assertEquals(30 + 1, exception.getStackTrace()[0].getLineNumber());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should lose the line number testing?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line numbers don't line up in the def and String case. I can put something together to keep it but in general script_stack is the thing we expect people to use. The line numbers leak a lot of painless internals that we strip from script_stack and script_stack is built from them anyway. I can keep them but it'll be funky.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care what we test it with, but it is something we return to users, so it should remain tested.

@nik9000
Copy link
Copy Markdown
Member Author

nik9000 commented Apr 19, 2017

@rjernst I pushed updates.

@nik9000 nik9000 merged commit db0a5e4 into elastic:master Apr 19, 2017
nik9000 added a commit that referenced this pull request Apr 19, 2017
`script_stack` is super useful when debugging Painless scripts
because it skips all the "weird" stuff involved that obfuscates
where the actual error is. It skips Painless's internals and
call site bootstrapping.

It works fine, but it didn't have many tests. This converts a
test that we had for line numbers into a test for the
`script_stack`. The line numbers test was an indirect test
for `script_stack`.
@nik9000
Copy link
Copy Markdown
Member Author

nik9000 commented Apr 19, 2017

Thanks for reviewing @rjernst!

jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Apr 19, 2017
* master:
  Add BucketMetricValue interface (elastic#24188)
  Enable index-time sorting (elastic#24055)
  Clarify elasticsearch user uid:gid mapping in Docker docs
  Update field-names-field.asciidoc (elastic#24178)
  ElectMasterService.hasEnoughMasterNodes should return false if no masters were found
  Remove Ubuntu 12.04 (elastic#24161)
  [Test] Add unit tests for InternalHDRPercentilesTests (elastic#24157)
  Replicate write failures (elastic#23314)
  Rename variable in translog simple commit test
  Strengthen translog commit with open view test
  Stronger check in translog prepare and commit test
  Fix translog prepare commit and commit test
  ingest-node.asciidoc - Clarify json processor (elastic#21876)
  Painless: more testing for script_stack (elastic#24168)
@nik9000 nik9000 deleted the painless_npes branch June 7, 2017 14:52
@clintongormley clintongormley added :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache and removed :Plugin Lang Painless labels Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >test Issues or PRs that are addressing/adding tests v5.5.0 v6.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants