Skip to content
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

Test uncaught panic produces error message #74

Merged
merged 4 commits into from
Sep 18, 2017

Conversation

SpencerPark
Copy link
Member

This adds a test for ensuring that executing code that panics without recovering returns an execute_reply with an error status as well as publishes an error message over IOPub.

Copy link
Contributor

@dwhitena dwhitena left a comment

Choose a reason for hiding this comment

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

Really great refactor of our testing pattern. Much better than my original. I have commented on some minor things. Also, one of the tests is failing for me:

go test -v
=== RUN   TestEvaluate
--- FAIL: TestEvaluate (1.00s)
        kernel_test.go:305: Should be able to evaluate valid code in notebook cells.
        kernel_test.go:310:   Evaluating code snippet 1/4.
        kernel_test.go:364: content["data"]["test/plain"] "test/plain" field not present
=== RUN   TestPanicGeneratesError
--- PASS: TestPanicGeneratesError (1.00s)
FAIL
exit status 1
FAIL    github.com/gopherdata/gophernotes       2.013s

kernel_test.go Outdated
const (
connectionKey = "a0436f6c-1916-498b-8eb9-e81ab9368e84"
sessionID = "ba65a05c-106a-4799-9a94-7f5631bbe216"
transport = "tcp"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the transport likely to change? Maybe we can inline that, as I doubt that we will be running with other types of transport?

kernel_test.go Outdated
sessionID = "ba65a05c-106a-4799-9a94-7f5631bbe216"
transport = "tcp"
ip = "127.0.0.1"
shellPort = 57503
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we parse the shell and iopub ports from the fixture connection file in the test init? That way, if ports change for any reason we only have to change them in one place.

kernel_test.go Outdated
iopubPort = 40885
)

type testJupyterClient struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

comment.

kernel_test.go Outdated
shellPort = 57503
iopubPort = 40885
)

Copy link
Contributor

Choose a reason for hiding this comment

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

To make this file a little more readable I suggest that we shuffle things around a little:

consts and vars

//==============================================================================

runTest TestMain and any init

//==============================================================================

Tests

//==============================================================================

Any other test helps including newTestJupyterClient, sendShellRequest, etc.

kernel_test.go Outdated
t.Fatal("iopub.SetSubscribe", err)
}

// wait for a second to give the tcp connection time to complete to avoid missing the early pub messages
Copy link
Contributor

Choose a reason for hiding this comment

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

period

kernel_test.go Outdated
client.sendShellRequest(t, request)
reply = client.recvShellReply(t, timeout)

// Read the expected 'busy' message and ensure it is in fact, a 'busy' message
Copy link
Contributor

Choose a reason for hiding this comment

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

period

kernel_test.go Outdated
t.Fatalf("Expected a 'busy' status message but got '%v'", execState)
}

// Read messages from the IOPub channel until an 'idle' message is received
Copy link
Contributor

Choose a reason for hiding this comment

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

period.

kernel_test.go Outdated
t.Fatalf("Expected a 'idle' status message but got '%v'", execState)
}

// Break from the loop as we don't expect any other IOPub messages after the 'idle'
Copy link
Contributor

Choose a reason for hiding this comment

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

period.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll stop nitpicking these. Just FYI.

func assertMsgTypeEquals(t *testing.T, msg ComposedMsg, expectedType string) {
t.Helper()

if msg.Header.MsgType != expectedType {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this should just be inline to make it more readable?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking the same but as it is already used 3 times and is likely to be used in future tests I figured it was nicer to avoid copy/pasting the message format everywhere. Then to clean up the format like we need to do with the failure char it's just one place that needs changing.

kernel_test.go Outdated
}

return ""
foundPublishedError := false
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just use var foundPublishedError bool as the zero-value is false.

@SpencerPark SpencerPark mentioned this pull request Sep 15, 2017
- Normalize fatal messages to be prefixed with a tab char and error
  symbol.
- Move test helpers to the bottom and better seperate them from the
  tests.
- Read kernel connection info from the test fixture file.
Copy link
Contributor

@dwhitena dwhitena left a comment

Choose a reason for hiding this comment

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

A couple minor nitpicks, then we can merge. I tested locally, and everything seems to work!

go test -v
=== RUN   TestEvaluate
--- PASS: TestEvaluate (4.02s)
        kernel_test.go:96: Should be able to evaluate valid code in notebook cells.
        kernel_test.go:101:   Evaluating code snippet 1/4.
        kernel_test.go:111:     ✓ Should return the correct cell output.
        kernel_test.go:101:   Evaluating code snippet 2/4.
        kernel_test.go:111:     ✓ Should return the correct cell output.
        kernel_test.go:101:   Evaluating code snippet 3/4.
        kernel_test.go:111:     ✓ Should return the correct cell output.
        kernel_test.go:101:   Evaluating code snippet 4/4.
        kernel_test.go:111:     ✓ Should return the correct cell output.
=== RUN   TestPanicGeneratesError
--- PASS: TestPanicGeneratesError (1.00s)
PASS
ok      github.com/gopherdata/gophernotes       5.044s

kernel_test.go Outdated
return value
}

// getString is a test helper that retrieves a value as a map[string]interface{} from the content at the given key.
Copy link
Contributor

Choose a reason for hiding this comment

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

Name in comment. FYI, running a linter at save time will catch these.

kernel_test.go Outdated
func TestMain(m *testing.M) {
os.Exit(runTest(m))
}

// runTest initializes the environment for the tests and allows for
// the proper exit if the test fails or succeeds.
func runTest(m *testing.M) int {
const connectionFile = "fixtures/connection_file.json"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe move the constants up above?

@dwhitena dwhitena merged commit b615ee7 into gopherdata:version-1 Sep 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants