func TestRPCProgressiveCallInterrupt(t *testing.T) {
	defer leaktest.Check(t)()
	callee, err := connectClient()
	if err != nil {
		t.Fatal("Failed to connect client:", err)
	}
	callerKiller := make(chan struct{})
	callerClosed := make(chan struct{})
	sentFinal := make(chan struct{})
	var sendProgErr error
	handler := func(ctx context.Context, inv *wamp.Invocation) client.InvokeResult {
		defer close(sentFinal)
		e := callee.SendProgress(ctx, wamp.List{"Alpha"}, nil)
		if e != nil {
			fmt.Println("Error sending Alpha progress:", e)
		}
		time.Sleep(50 * time.Millisecond)
		<-callerClosed
		e = callee.SendProgress(ctx, wamp.List{"Bravo"}, nil)
		if e != nil {
			fmt.Println("Error sending Bravo progress:", e)
		}
		e = callee.SendProgress(ctx, wamp.List{"Charlie"}, nil)
		if e != nil {
			fmt.Println("Error sending progress:", e)
		}
		time.Sleep(50 * time.Millisecond)
		e = callee.SendProgress(ctx, wamp.List{"Delta"}, nil)
		if e != nil && e.Error() != "caller not accepting progressive results" {
			sendProgErr = fmt.Errorf("error sending progress: %s", e)
		}
		e = callee.SendProgress(ctx, wamp.List{"Echo"}, nil)
		if e != nil && e.Error() != "caller not accepting progressive results" {
			sendProgErr = fmt.Errorf("error sending progress: %s", e)
		}
		return client.InvokeResult{Args: wamp.List{"final"}}
	}
	if err = callee.Register(progProc, handler, nil); err != nil {
		t.Fatal("Failed to register procedure:", err)
	}
	caller, err := connectClient()
	if err != nil {
		t.Fatal("Failed to connect client:", err)
	}
	progHandler := func(result *wamp.Result) {
		arg := result.Arguments[0].(string)
		fmt.Println("Caller received progress response:", arg)
		select {
		case callerKiller <- struct{}{}:
		default:
		}
	}
	recvProgErr := make(chan error)
	go func() {
		ctx := context.Background()
		_, e := caller.Call(ctx, progProc, nil, nil, nil, progHandler)
		recvProgErr <- e
	}()
	<-callerKiller
	err = caller.Close()
	if err != nil {
		t.Error("Failed to disconnect client:", err)
	}
	err = <-recvProgErr
	if err != client.ErrNotConn {
		t.Errorf("unexpected error returned fom CallProgress: %s", err)
	}
	<-caller.Done()
	close(callerClosed)
	select {
	case <-sentFinal:
		t.Error("Callee should not have finished sending progressive results")
	default:
	}
	<-sentFinal
	if sendProgErr != nil {
		t.Error(sendProgErr)
	}
	err = callee.Close()
	if err != nil {
		t.Error("Failed to disconnect client:", err)
	}
}
Test that killing the caller, while in the middle of receiving progressive
results, is handled correctly by both the closed caller and the callee.
package aat
import (
	"context"
	"fmt"
	"testing"
	"time"
	"github.com/fortytw2/leaktest"
	"github.com/gammazero/nexus/v3/client"
	"github.com/gammazero/nexus/v3/wamp"
)
const (
	progProc  = "nexus.test.progproc"
	chunkProc = "example.progress.text"
)
func TestRPCProgressiveCallResults(t *testing.T) {
	defer leaktest.Check(t)()
	callee, err := connectClient()
	if err != nil {
		t.Fatal("Failed to connect client:", err)
	}
	if !callee.HasFeature(wamp.RoleDealer, wamp.FeatureProgCallResults) {
		t.Error("Dealer does not support", wamp.FeatureProgCallResults)
	}
	handler := func(ctx context.Context, inv *wamp.Invocation) client.InvokeResult {
		e := callee.SendProgress(ctx, wamp.List{"Alpha"}, nil)
		if e != nil {
			fmt.Println("Error sending Alpha progress:", e)
		}
		e = callee.SendProgress(ctx, wamp.List{"Bravo"}, nil)
		if e != nil {
			fmt.Println("Error sending Bravo progress:", e)
		}
		e = callee.SendProgress(ctx, wamp.List{"Charlie"}, nil)
		if e != nil {
			fmt.Println("Error sending Charlie progress:", e)
		}
		var sum int64
		for _, arg := range inv.Arguments {
			n, ok := wamp.AsInt64(arg)
			if ok {
				sum += n
			}
		}
		return client.InvokeResult{Args: wamp.List{sum}}
	}
	if err = callee.Register(progProc, handler, nil); err != nil {
		t.Fatal("Failed to register procedure:", err)
	}
	caller, err := connectClient()
	if err != nil {
		t.Fatal("Failed to connect client:", err)
	}
	progCount := 0
	progHandler := func(result *wamp.Result) {
		arg := result.Arguments[0].(string)
		if (progCount == 0 && arg != "Alpha") || (progCount == 1 && arg != "Bravo") || (progCount == 2 && arg != "Charlie") {
			return
		}
		progCount++
	}
	callArgs := wamp.List{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
	ctx := context.Background()
	result, err := caller.Call(ctx, progProc, nil, callArgs, nil, progHandler)
	if err != nil {
		t.Fatal("Failed to call procedure:", err)
	}
	sum, ok := wamp.AsInt64(result.Arguments[0])
	if !ok {
		t.Fatal("Could not convert result to int64")
	}
	if sum != 55 {
		t.Fatal("Wrong result:", sum)
	}
	if progCount != 3 {
		t.Fatal("Expected progCount == 3")
	}
	if err = callee.Unregister(progProc); err != nil {
		t.Fatal("Failed to unregister procedure:", err)
	}
	err = caller.Close()
	if err != nil {
		t.Fatal("Failed to disconnect client:", err)
	}
	err = callee.Close()
	if err != nil {
		t.Fatal("Failed to disconnect client:", err)
	}
}