Skip to content

Commit

Permalink
[FAB-8770] Remove extra SDK instances for int tests
Browse files Browse the repository at this point in the history
This change reduces the number of SDK instances to improve
test speed. Some log messages are also reduced to debug
to improve log readability.

Change-Id: I7689058d9cf1f2c671d1124158cab88bde712266
Signed-off-by: Troy Ronda <[email protected]>
  • Loading branch information
troyronda committed Mar 10, 2018
1 parent 0520153 commit 2bfab1c
Show file tree
Hide file tree
Showing 17 changed files with 281 additions and 235 deletions.
2 changes: 1 addition & 1 deletion pkg/core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func initConfig(c *Config) (*Config, error) {
}

for _, logModule := range logModules {
logger.Infof("config %s logging level is set to: %s", logModule, logging.ParseString(logging.GetLevel(logModule)))
logger.Debugf("config %s logging level is set to: %s", logModule, logging.ParseString(logging.GetLevel(logModule)))
}

//Compile the entityMatchers
Expand Down
4 changes: 2 additions & 2 deletions pkg/fabsdk/provider/fabpvdr/fabpvdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ func getEventClient(ctx context.Client, chConfig fab.ChannelCfg) (fab.EventClien
// look at the EventServiceType specified in the config file.
switch ctx.Config().EventServiceType() {
case core.DeliverEventServiceType:
logger.Infof("Using deliver events")
logger.Debugf("Using deliver events")
return deliverclient.New(ctx, chConfig)
case core.EventHubEventServiceType:
logger.Infof("Using event hub events")
logger.Debugf("Using event hub events")
return eventhubclient.New(ctx, chConfig, eventhubclient.WithBlockEvents())
default:
return nil, errors.Errorf("unsupported event service type: %d", ctx.Config().EventServiceType())
Expand Down
9 changes: 3 additions & 6 deletions test/integration/e2e/end_to_end.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
//clientContext allows creation of transactions using the supplied identity as the credential.
clientContext := sdk.Context(fabsdk.WithUser(orgAdmin), fabsdk.WithOrg(ordererOrgName))

// Channel management client is responsible for managing channels (create/update channel)
// Resource management client is responsible for managing channels (create/update channel)
// Supply user that has privileges to create channel (in this case orderer admin)
chMgmtClient, err := resmgmt.New(clientContext)
resMgmtClient, err := resmgmt.New(clientContext)
if err != nil {
t.Fatalf("Failed to create channel management client: %s", err)
}
Expand All @@ -70,7 +70,7 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
req := resmgmt.SaveChannelRequest{ChannelID: channelID,
ChannelConfig: path.Join("../../../", metadata.ChannelConfigPath, "mychannel.tx"),
SigningIdentities: []fab.IdentityContext{adminIdentity}}
if err = chMgmtClient.SaveChannel(req); err != nil {
if err = resMgmtClient.SaveChannel(req); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -123,9 +123,6 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
t.Fatalf("Failed to create new channel client: %s", err)
}

// Release all channel client resources
defer client.Close()

response, err := client.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()})
if err != nil {
t.Fatalf("Failed to query funds: %s", err)
Expand Down
3 changes: 0 additions & 3 deletions test/integration/e2e/no_orderer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ func runWithNoOrdererConfig(t *testing.T, configOpt core.ConfigProvider, sdkOpts
t.Fatalf("Failed to create new channel client: %s", err)
}

// Release all channel client resources
defer client.Close()

response, err := client.Query(channel.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()})
if err != nil {
t.Fatalf("Failed to query funds: %s", err)
Expand Down
23 changes: 11 additions & 12 deletions test/integration/fab/channel_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/client/ledger"
"github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/pkg/errors"
)
Expand All @@ -29,20 +28,18 @@ const (
orgName = org1Name
)

var sdkConfigFile = "../" + integration.ConfigTestFile

func initializeLedgerTests(t *testing.T) (*fabsdk.FabricSDK, []fab.Peer) {
sdk, err := fabsdk.New(config.FromFile(sdkConfigFile))
if err != nil {
t.Fatalf("SDK init failed: %v", err)
}
// Using shared SDK instance to increase test speed.
sdk := mainSDK

//var sdkConfigFile = "../" + integration.ConfigTestFile
// sdk, err := fabsdk.New(config.FromFile(sdkConfigFile))
// if err != nil {
// t.Fatalf("SDK init failed: %v", err)
// }
// Get signing identity that is used to sign create channel request

adminIdentity, err := integration.GetSigningIdentity(sdk, "Admin", orgName)
if err != nil {
t.Fatal(err)
}

if err != nil {
t.Fatalf("failed to load signing identity: %s", err)
}
Expand All @@ -65,7 +62,9 @@ func TestLedgerQueries(t *testing.T) {

// Setup tests with a random chaincode ID.
sdk, targets := initializeLedgerTests(t)
defer sdk.Close()

// Using shared SDK instance to increase test speed.
//defer sdk.Close()

chaincodeID := integration.GenerateRandomID()
if err := integration.InstallAndInstantiateExampleCC(sdk, fabsdk.WithUser("Admin"), orgName, chaincodeID); err != nil {
Expand Down
12 changes: 7 additions & 5 deletions test/integration/fab/fabric_ca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,25 @@ const (
)

func TestEnrollOrg2(t *testing.T) {
// Using shared SDK instance to increase test speed.
sdk := mainSDK

cryptoSuiteProvider, err := cryptosuite.GetSuiteByConfig(testFabricConfig)
cryptoSuiteProvider, err := cryptosuite.GetSuiteByConfig(sdk.Config())
if err != nil {
t.Fatalf("Failed getting cryptosuite from config : %s", err)
}

stateStore, err := kvs.New(&kvs.FileKeyValueStoreOptions{Path: testFabricConfig.CredentialStorePath()})
stateStore, err := kvs.New(&kvs.FileKeyValueStoreOptions{Path: sdk.Config().CredentialStorePath()})
if err != nil {
t.Fatalf("CreateNewFileKeyValueStore failed: %v", err)
}

identityManager, err := identitymgr.New(org2Name, stateStore, cryptoSuiteProvider, testFabricConfig)
identityManager, err := identitymgr.New(org2Name, stateStore, cryptoSuiteProvider, sdk.Config())
if err != nil {
t.Fatalf("identitymgr.New failed: %v", err)
}

caClient, err := msp.New(org2Name, identityManager, stateStore, cryptoSuiteProvider, testFabricConfig)
caClient, err := msp.New(org2Name, identityManager, stateStore, cryptoSuiteProvider, sdk.Config())
if err != nil {
t.Fatalf("caclient.New failed: %v", err)
}
Expand All @@ -49,7 +51,7 @@ func TestEnrollOrg2(t *testing.T) {
}

//clean up the Keystore file, as its affecting other tests
err = os.RemoveAll(testFabricConfig.CredentialStorePath())
err = os.RemoveAll(sdk.Config().CredentialStorePath())
if err != nil {
t.Fatalf("Error deleting keyvalue store file: %v", err)
}
Expand Down
39 changes: 20 additions & 19 deletions test/integration/fab/install_chaincode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@ package fab

import (
"math/rand"
"path"
"strconv"
"strings"
"testing"

"github.com/hyperledger/fabric-sdk-go/pkg/context"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
packager "github.com/hyperledger/fabric-sdk-go/pkg/fab/ccpackager/gopackager"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource/api"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/hyperledger/fabric-sdk-go/test/integration"
"github.com/hyperledger/fabric-sdk-go/test/metadata"
"github.com/pkg/errors"
)

Expand All @@ -32,22 +29,26 @@ const (

func TestChaincodeInstal(t *testing.T) {

testSetup := &integration.BaseSetupImpl{
ConfigFile: "../" + integration.ConfigTestFile,
ChannelID: "mychannel",
OrgID: org1Name,
ChannelConfig: path.Join("../../../", metadata.ChannelConfigPath, "mychannel.tx"),
}

sdk, err := fabsdk.New(config.FromFile(testSetup.ConfigFile))
if err != nil {
t.Fatalf("Failed to create new SDK: %s", err)
}
defer sdk.Close()

if err := testSetup.Initialize(sdk); err != nil {
t.Fatalf(err.Error())
}
// Using shared SDK instance to increase test speed.
sdk := mainSDK
testSetup := mainTestSetup

//testSetup := &integration.BaseSetupImpl{
// ConfigFile: "../" + integration.ConfigTestFile,
// ChannelID: "mychannel",
// OrgID: org1Name,
// ChannelConfig: path.Join("../../../", metadata.ChannelConfigPath, "mychannel.tx"),
//}

//sdk, err := fabsdk.New(config.FromFile(testSetup.ConfigFile))
//if err != nil {
// t.Fatalf("Failed to create new SDK: %s", err)
//}
//defer sdk.Close()

//if err := testSetup.Initialize(sdk); err != nil {
// t.Fatalf(err.Error())
//}

testChaincodeInstallUsingChaincodePath(t, sdk, testSetup)

Expand Down
42 changes: 15 additions & 27 deletions test/integration/fab/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
"path"
"testing"

"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/hyperledger/fabric-sdk-go/test/integration"
"github.com/hyperledger/fabric-sdk-go/test/metadata"
)

var testFabricConfig core.Config
var mainSDK *fabsdk.FabricSDK
var mainTestSetup *integration.BaseSetupImpl
var mainChaincodeID string

func TestMain(m *testing.M) {
setup()
Expand All @@ -28,26 +29,6 @@ func TestMain(m *testing.M) {
}

func setup() {
// do any test setup for all tests here...
var err error

testSetup := integration.BaseSetupImpl{
ConfigFile: "../" + integration.ConfigTestFile,
}

testFabricConfig, err = testSetup.InitConfig()()
if err != nil {
fmt.Printf("Failed InitConfig [%s]\n", err)
os.Exit(1)
}
}

func teardown() {
// do any teadown activities here ..
testFabricConfig = nil
}

func initializeTests(t *testing.T, chainCodeID string) (integration.BaseSetupImpl, *fabsdk.FabricSDK) {
testSetup := integration.BaseSetupImpl{
ConfigFile: "../" + integration.ConfigTestFile,

Expand All @@ -58,16 +39,23 @@ func initializeTests(t *testing.T, chainCodeID string) (integration.BaseSetupImp

sdk, err := fabsdk.New(config.FromFile(testSetup.ConfigFile))
if err != nil {
t.Fatalf("Failed to create new SDK: %s", err)
panic(fmt.Sprintf("Failed to create new SDK: %s", err))
}

if err := testSetup.Initialize(sdk); err != nil {
t.Fatalf(err.Error())
panic(err.Error())
}

if err := integration.InstallAndInstantiateCC(sdk, fabsdk.WithUser("Admin"), testSetup.OrgID, chainCodeID, "github.com/events_cc", "v0", integration.GetDeployPath(), nil); err != nil {
t.Fatalf("InstallAndInstantiateCC return error: %v", err)
chaincodeID := integration.GenerateRandomID()
if err := integration.InstallAndInstantiateExampleCC(sdk, fabsdk.WithUser("Admin"), testSetup.OrgID, chaincodeID); err != nil {
panic(fmt.Sprintf("InstallAndInstantiateExampleCC return error: %v", err))
}

return testSetup, sdk
mainSDK = sdk
mainTestSetup = &testSetup
mainChaincodeID = chaincodeID
}

func teardown() {
mainSDK.Close()
}
10 changes: 6 additions & 4 deletions test/integration/fab/resource_queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/context"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource"
"github.com/hyperledger/fabric-sdk-go/test/integration"
)

func TestChannelQueries(t *testing.T) {
chaincodeID := integration.GenerateRandomID()
testSetup, sdk := initializeTests(t, chaincodeID)
defer sdk.Close()
// Using shared SDK instance to increase test speed.
sdk := mainSDK
testSetup := mainTestSetup
chaincodeID := mainChaincodeID

//chaincodeID := integration.GenerateRandomID()

// Low level resource
client, err := getContext(sdk, "Admin", orgName)
Expand Down
51 changes: 26 additions & 25 deletions test/integration/fab/transient_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,43 @@ SPDX-License-Identifier: Apache-2.0
package fab

import (
"path"
"testing"

"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/txn"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/hyperledger/fabric-sdk-go/test/integration"
"github.com/hyperledger/fabric-sdk-go/test/metadata"
"github.com/pkg/errors"
)

// TestTransient ...
func TestTransient(t *testing.T) {

testSetup := integration.BaseSetupImpl{
ConfigFile: "../" + integration.ConfigTestFile,
ChannelID: "mychannel",
OrgID: org1Name,
ChannelConfig: path.Join("../../../", metadata.ChannelConfigPath, "mychannel.tx"),
}

sdk, err := fabsdk.New(config.FromFile(testSetup.ConfigFile))
if err != nil {
t.Fatalf("Failed to create new SDK: %s", err)
}
defer sdk.Close()

if err := testSetup.Initialize(sdk); err != nil {
t.Fatalf(err.Error())
}

chaincodeID := integration.GenerateRandomID()
if err := integration.InstallAndInstantiateExampleCC(sdk, fabsdk.WithUser("Admin"), testSetup.OrgID, chaincodeID); err != nil {
t.Fatalf("InstallAndInstantiateExampleCC return error: %v", err)
}
// Using shared SDK instance to increase test speed.
sdk := mainSDK
testSetup := mainTestSetup
chaincodeID := mainChaincodeID

//testSetup := integration.BaseSetupImpl{
// ConfigFile: "../" + integration.ConfigTestFile,
// ChannelID: "mychannel",
// OrgID: org1Name,
// ChannelConfig: path.Join("../../../", metadata.ChannelConfigPath, "mychannel.tx"),
//}

//sdk, err := fabsdk.New(config.FromFile(testSetup.ConfigFile))
//if err != nil {
// t.Fatalf("Failed to create new SDK: %s", err)
//}
//defer sdk.Close()

//if err := testSetup.Initialize(sdk); err != nil {
// t.Fatalf(err.Error())
//}

//chaincodeID := integration.GenerateRandomID()
//if err := integration.InstallAndInstantiateExampleCC(sdk, fabsdk.WithUser("Admin"), testSetup.OrgID, chaincodeID); err != nil {
// t.Fatalf("InstallAndInstantiateExampleCC return error: %v", err)
//}

fcn := "invoke"
transientData := "Transient data test..."
Expand Down
Loading

0 comments on commit 2bfab1c

Please sign in to comment.