@@ -409,6 +409,82 @@ func (gs *messageOrderGS) HandleDirect(process *gen.ServerProcess, message inter
409
409
return nil , fmt .Errorf ("incorrect direct call" )
410
410
}
411
411
412
+ type GSCallPanic struct {
413
+ gen.Server
414
+ }
415
+
416
+ func (gs * GSCallPanic ) Init (process * gen.ServerProcess , args ... etf.Term ) error {
417
+ return nil
418
+ }
419
+
420
+ func (gs * GSCallPanic ) HandleCall (process * gen.ServerProcess , from gen.ServerFrom , message etf.Term ) (etf.Term , gen.ServerStatus ) {
421
+ m := message .(string )
422
+ if m == "panic" {
423
+ panic ("test" )
424
+ }
425
+
426
+ return "ok" , gen .ServerStatusOK
427
+ }
428
+
429
+ func (gs * GSCallPanic ) HandleDirect (process * gen.ServerProcess , message interface {}) (interface {}, error ) {
430
+
431
+ pids , ok := message .([]etf.Pid )
432
+ if ! ok {
433
+ return nil , fmt .Errorf ("not a pid" )
434
+ }
435
+ if _ , err := process .CallWithTimeout (pids [0 ], "panic" , 1 ); err == nil {
436
+ return nil , fmt .Errorf ("must be error here" )
437
+ }
438
+
439
+ v , err := process .Call (pids [1 ], "test" )
440
+ if err != nil {
441
+ return nil , err
442
+ }
443
+ if v .(string ) != "ok" {
444
+ return nil , fmt .Errorf ("wrong result %#v" , v )
445
+ }
446
+
447
+ return nil , nil
448
+ }
449
+
450
+ func TestServerCallServerWithPanic (t * testing.T ) {
451
+ fmt .Printf ("\n === Test Server. Making a Call to Server with panic (issue 86) \n " )
452
+ fmt .Printf ("Starting node: nodeGSCallWithPanic1@localhost: " )
453
+ node1 , err1 := ergo .StartNode ("nodeGSCallWithPanic1@localhost" , "cookies" , node.Options {})
454
+ if err1 != nil {
455
+ t .Fatal ("can't start node" , err1 )
456
+ } else {
457
+ fmt .Println ("OK" )
458
+ }
459
+ fmt .Printf ("Starting node: nodeGSCallWithPanic2@localhost: " )
460
+ node2 , err2 := ergo .StartNode ("nodeGSCallWithPanic2@localhost" , "cookies" , node.Options {})
461
+ if err2 != nil {
462
+ t .Fatal ("can't start node" , err2 )
463
+ } else {
464
+ fmt .Println ("OK" )
465
+ }
466
+
467
+ p1n1 , err := node1 .Spawn ("" , gen.ProcessOptions {}, & GSCallPanic {})
468
+ if err != nil {
469
+ t .Fatal (err )
470
+ }
471
+ p1n2 , err := node2 .Spawn ("" , gen.ProcessOptions {}, & GSCallPanic {})
472
+ if err != nil {
473
+ t .Fatal (err )
474
+ }
475
+ p2n2 , err := node2 .Spawn ("" , gen.ProcessOptions {}, & GSCallPanic {})
476
+ if err != nil {
477
+ t .Fatal (err )
478
+ }
479
+
480
+ pids := []etf.Pid {p1n2 .Self (), p2n2 .Self ()}
481
+
482
+ if _ , err := p1n1 .Direct (pids ); err != nil {
483
+ t .Fatal (err )
484
+ }
485
+ fmt .Println ("OK" )
486
+ }
487
+
412
488
func TestServerMessageOrder (t * testing.T ) {
413
489
fmt .Printf ("\n === Test Server message order\n " )
414
490
fmt .Printf ("Starting node: nodeGS1MessageOrder@localhost: " )
0 commit comments