github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/systests/account_deadlock_test.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package systests
     5  
     6  // Test various RPCs that are used mainly in other clients but not by the CLI.
     7  
     8  import (
     9  	"testing"
    10  	"time"
    11  
    12  	"github.com/keybase/client/go/client"
    13  	"github.com/keybase/client/go/libkb"
    14  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    15  	"github.com/keybase/client/go/service"
    16  	context "golang.org/x/net/context"
    17  )
    18  
    19  func TestAccountDeadlock(t *testing.T) {
    20  	tc := setupTest(t, "deadlock")
    21  	defer tc.Cleanup()
    22  	tc2 := cloneContext(tc)
    23  	defer tc2.Cleanup()
    24  
    25  	stopCh := make(chan error)
    26  	svc := service.NewService(tc.G, false)
    27  	startCh := svc.GetStartChannel()
    28  	go func() {
    29  		err := svc.Run()
    30  		if err != nil {
    31  			t.Logf("Running the service produced an error: %v", err)
    32  		}
    33  		stopCh <- err
    34  	}()
    35  
    36  	<-startCh
    37  
    38  	signupDoneCh := make(chan struct{})
    39  
    40  	go func() {
    41  		issueSignup(t, tc2.G)
    42  		signupDoneCh <- struct{}{}
    43  	}()
    44  
    45  	currentStatusLoop(t, tc2.G, signupDoneCh)
    46  
    47  	if err := CtlStop(tc2.G); err != nil {
    48  		t.Fatal(err)
    49  	}
    50  
    51  	// If the server failed, it's also an error
    52  	if err := <-stopCh; err != nil {
    53  		t.Fatal(err)
    54  	}
    55  }
    56  
    57  func issueSignup(t *testing.T, g *libkb.GlobalContext) {
    58  	cli, err := client.GetSignupClient(g)
    59  	if err != nil {
    60  		t.Fatalf("failed to get new identifyclient: %v", err)
    61  	}
    62  
    63  	id, err := libkb.RandString("", 5)
    64  	if err != nil {
    65  		t.Fatalf("Failed to get a random string: %s", err)
    66  	}
    67  
    68  	arg := keybase1.SignupArg{
    69  		Email:      "test+" + id + "@keyba.se",
    70  		Passphrase: "strong-password",
    71  		Username:   "t_" + id,
    72  		DeviceName: "dev0",
    73  		InviteCode: "202020202020202020202020",
    74  		DeviceType: keybase1.DeviceType_DESKTOP,
    75  	}
    76  
    77  	if _, err := cli.Signup(context.TODO(), arg); err != nil {
    78  		t.Fatalf("signup failed: %s", err)
    79  	}
    80  }
    81  
    82  func currentStatusLoop(t *testing.T, g *libkb.GlobalContext, stopCh chan struct{}) {
    83  	cli, err := client.GetSessionClient(g)
    84  	if err != nil {
    85  		t.Fatal(err)
    86  	}
    87  	for {
    88  		select {
    89  		case <-stopCh:
    90  			return
    91  		case <-time.After(50 * time.Millisecond):
    92  			_, err := cli.CurrentSession(context.TODO(), 0)
    93  			if err != nil {
    94  				if _, ok := err.(libkb.NoSessionError); !ok {
    95  					t.Fatal(err)
    96  				}
    97  			}
    98  		}
    99  	}
   100  }