func TestParallelInitClose(t *testing.T) { // TODO: complete this conf := utils.NodeConfiguration{Type: "client", Name: "userthread"} RegisterClient(conf.Name, nil, conf.GetEnrollmentID(), conf.GetEnrollmentPWD()) done := make(chan bool) go func() { for i := 0; i < 5; i++ { client, err := InitClient(conf.Name, nil) if err != nil { t.Log("Init failed") } time.Sleep(1 * time.Second) err = CloseClient(client) if err != nil { t.Log("Close failed") } } done <- true }() go func() { for i := 0; i < 5; i++ { client, err := InitClient(conf.Name, nil) if err != nil { t.Log("Init failed") } time.Sleep(2 * time.Second) err = CloseClient(client) if err != nil { t.Log("Close failed") } } done <- true }() go func() { for i := 0; i < 5; i++ { client, err := InitClient(conf.Name, nil) if err != nil { t.Log("Init failed") } time.Sleep(1 * time.Second) err = CloseClient(client) if err != nil { t.Log("Close failed") } } done <- true }() for i := 0; i < 3; i++ { t.Log("Waiting") <-done t.Log("+1") } // }
func TestParallelInitClose(t *testing.T) { // TODO: complete this conf := utils.NodeConfiguration{Type: "client", Name: "userthread"} RegisterClient(conf.Name, nil, conf.GetEnrollmentID(), conf.GetEnrollmentPWD()) done := make(chan bool) n := 10 for i := 0; i < n; i++ { go func() { for i := 0; i < 5; i++ { client, err := InitClient(conf.Name, nil) if err != nil { t.Log("Init failed") } cis := &obc.ChaincodeInvocationSpec{ ChaincodeSpec: &obc.ChaincodeSpec{ Type: obc.ChaincodeSpec_GOLANG, ChaincodeID: &obc.ChaincodeID{Path: "Contract001"}, CtorMsg: nil, ConfidentialityLevel: obc.ConfidentialityLevel_CONFIDENTIAL, }, } for i := 0; i < 20; i++ { uuid := util.GenerateUUID() client.NewChaincodeExecute(cis, uuid) } err = CloseClient(client) if err != nil { t.Log("Close failed") } } done <- true }() } for i := 0; i < n; i++ { log.Info("Waiting") <-done log.Info("+1") } log.Info("Test Finished!") // }
func initClients() error { // Deployer deployerConf := utils.NodeConfiguration{Type: "client", Name: "user1"} if err := RegisterClient(deployerConf.Name, ksPwd, deployerConf.GetEnrollmentID(), deployerConf.GetEnrollmentPWD()); err != nil { return err } var err error deployer, err = InitClient(deployerConf.Name, ksPwd) if err != nil { return err } // Invoker invokerConf := utils.NodeConfiguration{Type: "client", Name: "user2"} if err := RegisterClient(invokerConf.Name, ksPwd, invokerConf.GetEnrollmentID(), invokerConf.GetEnrollmentPWD()); err != nil { return err } invoker, err = InitClient(invokerConf.Name, ksPwd) if err != nil { return err } return nil }
func initValidators() error { // Register conf := utils.NodeConfiguration{Type: "validator", Name: "validator"} err := RegisterValidator(conf.Name, ksPwd, conf.GetEnrollmentID(), conf.GetEnrollmentPWD()) if err != nil { return err } // Verify that a second call to Register fails err = RegisterValidator(conf.Name, ksPwd, conf.GetEnrollmentID(), conf.GetEnrollmentPWD()) if err != nil { return err } // Init validator, err = InitValidator(conf.Name, ksPwd) if err != nil { return err } err = RegisterValidator(conf.Name, ksPwd, conf.GetEnrollmentID(), conf.GetEnrollmentPWD()) if err != nil { return err } return err }
func TestRegistrationSameEnrollIDDifferentRole(t *testing.T) { conf := utils.NodeConfiguration{Type: "client", Name: "TestRegistrationSameEnrollIDDifferentRole"} if err := RegisterClient(conf.Name, nil, conf.GetEnrollmentID(), conf.GetEnrollmentPWD()); err != nil { t.Fatalf("Failed client registration [%s]", err) } if err := RegisterValidator(conf.Name, nil, conf.GetEnrollmentID(), conf.GetEnrollmentPWD()); err == nil { t.Fatalf("Reusing the same enrollment id must be forbidden", err) } if err := RegisterPeer(conf.Name, nil, conf.GetEnrollmentID(), conf.GetEnrollmentPWD()); err == nil { t.Fatalf("Reusing the same enrollment id must be forbidden", err) } }
func initPeers() error { // Register conf := utils.NodeConfiguration{Type: "peer", Name: "peer"} err := RegisterPeer(conf.Name, nil, conf.GetEnrollmentID(), conf.GetEnrollmentPWD()) if err != nil { return err } // Verify that a second call to Register fails err = RegisterPeer(conf.Name, nil, conf.GetEnrollmentID(), conf.GetEnrollmentPWD()) if err != nil { return err } // Init peer, err = InitPeer(conf.Name, nil) if err != nil { return err } err = RegisterPeer(conf.Name, nil, conf.GetEnrollmentID(), conf.GetEnrollmentPWD()) if err != nil { return err } return err }