newTestJupyterClient creates and connects a fresh client to the kernel. Upon error, newTestJupyterClient will Fail the test.
(t *testing.T)
| 334 | // newTestJupyterClient creates and connects a fresh client to the kernel. Upon error, newTestJupyterClient |
| 335 | // will Fail the test. |
| 336 | func newTestJupyterClient(t *testing.T) (testJupyterClient, func()) { |
| 337 | t.Helper() |
| 338 | |
| 339 | var ( |
| 340 | err error |
| 341 | ctx = context.Background() |
| 342 | addrShell = fmt.Sprintf("%s://%s:%d", transport, ip, shellPort) |
| 343 | addrIO = fmt.Sprintf("%s://%s:%d", transport, ip, iopubPort) |
| 344 | ) |
| 345 | |
| 346 | // Prepare the shell socket. |
| 347 | shell := zmq4.NewReq(ctx) |
| 348 | if err = shell.Dial(addrShell); err != nil { |
| 349 | t.Fatalf("\t%s shell.Connect: %s", failure, err) |
| 350 | } |
| 351 | |
| 352 | // Prepare the IOPub socket. |
| 353 | iopub := zmq4.NewSub(ctx) |
| 354 | if err = iopub.Dial(addrIO); err != nil { |
| 355 | t.Fatalf("\t%s iopub.Connect: %s", failure, err) |
| 356 | } |
| 357 | |
| 358 | if err = iopub.SetOption(zmq4.OptionSubscribe, ""); err != nil { |
| 359 | t.Fatalf("\t%s iopub.SetSubscribe: %s", failure, err) |
| 360 | } |
| 361 | |
| 362 | // Wait for a second to give the tcp connection time to complete to avoid missing the early pub messages. |
| 363 | time.Sleep(1 * time.Second) |
| 364 | |
| 365 | return testJupyterClient{shell, iopub}, func() { |
| 366 | if err := shell.Close(); err != nil { |
| 367 | t.Errorf("\t%s shell.Close: %s", failure, err) |
| 368 | } |
| 369 | if err = iopub.Close(); err != nil { |
| 370 | t.Errorf("\t%s iopub.Close: %s", failure, err) |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | // sendShellRequest sends a message to the kernel over the shell channel. Upon error, sendShellRequest |
| 376 | // will Fail the test. |
no outgoing calls
no test coverage detected