hyperledger-caliper / caliper

A blockchain benchmark framework to measure performance of multiple blockchain solutions https://wiki.hyperledger.org/display/caliper
https://hyperledger-caliper.github.io/caliper/
Apache License 2.0
655 stars 404 forks source link

Hyperledger caliper with composer tests fail when running #385

Closed ghost closed 5 years ago

ghost commented 5 years ago

Context

I have created a test environment locally and now I am trying to test my transactions, the issue here is that all my tests fail. I do not know why, as when I use any of the other test folders like perishable-network or vehicle-lifecycle-network, with my fabric network some of the tests succeed.

This is the output of me running my own tests on the files below, I want to know why they fail and how i can possibly fix the issues:

failed

Expected Behavior

Expecting some of the test iterations to succeed

Actual Behavior

Every test iteration fails

Possible Fix

Steps to Reproduce

  1. My logic.js file
    
    /**
    *A participant of type home in the network
    */
    participant Home identified by homeId {
    o   String homeId
    -->   Owner    homeOwner
    o   Address   address
    --> Service[] services optional
    --> Device[] devices optional 
    }
    /**
    *A participant of type Service in the network
    */
    participant Service identified by serviceId{
    o   String serviceId
    o   String serviceName
    }

/* A participant of type Owner in the network */ participant Owner identified by personId{ o String personId o String firstname optional o String lastname optional }

/* An asset of type Device in the network */ participant Device identified by deviceId{ o String deviceId --> Home home o String deviceLocation o Double minimumTemperature o Double maximumTemperature o String nickname o DeviceReading[] deviceReadings optional }

abstract transaction DeviceTransaction{ --> Device device }

concept Address{ o String street o String city }

transaction DeviceReading extends DeviceTransaction{ o Double temperature o String readingTime o String readingDate }

transaction AddingHome{ --> Home home }

transaction AddDevice extends DeviceTransaction{ }

event HomeAdded{ --> Owner homeOwner --> Home home o String message }

event DeviceAdded{ --> Device device o String message }

event DeviceReadingSent{ o String message --> Device device }

event TemperatureThresholdEvent{ o String message o Double temperature o String readingTime }

transaction SetupDemo{

}

2. my logic.js file

'use strict';

/***

const removeExisting = require('../composer-test-utils').clearAll; const logger = require('../../../src/comm/util').getLogger('smarthomes.js'); const os = require('os'); const uuid = os.hostname() + process.pid; // UUID for client within test

module.exports.info = 'Smarthomes Network Performance Test';

let bc; let busNetConnection; let testAssetNum; let factory; let assetId; let testTransaction; const namespace = 'org.blockchain.model';

module.exports.init = async function(blockchain, context, args) { // Create Participants and Assets to use in main test bc = blockchain; busNetConnection = context; testAssetNum = args.testAssets; testTransaction = args.transaction; assetId = 0;

factory = busNetConnection.getBusinessNetwork().getFactory();

let homeRegistry = await busNetConnection.getParticipantRegistry(namespace + '.Home');
let ownerRegistry = await busNetConnection.getParticipantRegistry(namespace + '.Owner');
let deviceRegistry = await busNetConnection.getParticipantRegistry(namespace + '.Device');

let homes = new Array();
let owners = new Array();
let devices = new Array();
let populated;

switch(testTransaction){
case 'DeviceReading':
    //Received a device reading, require Homes, owners and devices. 
        // Test specified number of Owners
    owners.push(factory.newResource(namespace, 'Owner', 'OWNER_' + uuid + '_0'));

    // Test specified number of Homes
    for(let i = 0; i<testAssetNum; i++){
        let home = factory.newResource(namespace, 'Home', 'HOME_' + uuid + '_'+i);
        let homeAddress = factory.newConcept(namespace, 'Address');
        homeAddress.street = 'Problemveien '+i;
        homeAddress.city ='Oslo';
        home.address = homeAddress;
        home.homeOwner = factory.newRelationship(namespace,'Owner','OWNER_' +uuid + '_0'); 
        homes.push(home);
    }
    //Test specified number of Devices
    for(let i = 0; i <testAssetNum; i++){
        let device = factory.newResource(namespace,'Device','DEVICE_'+uuid + '_' +i); 
        device.deviceLocation = 'Kitchen'; 
        device.minimumTemperature = 25.0; 
        device.maximumTemperature = 30.0
        device.nickname = uuid;
        device.home = factory.newRelationship(namespace, 'Home', 'HOME_' + uuid + '_0');
        devices.push(device);  
    }
    populated = await ownerRegistry.exists(owners[0].getIdentifier());
    break;
case 'addingHome':
    //Transaction to add a new Home

    let home = factory.newResource(namespace,'Home', 'HOME_'+ uuid + '_0');
    home.homeOwner = factory.newRelationship(namespace,'Owner', factory.newResource(namespace,'Owner','OWNER_'+uuid + '_'+testAssetNum)); 
    let homeAddress = factory.newConcept(namespace, 'Address');
    homeAddress.street = 'Problemveien 221';
    homeAddress.city ='Oslo';
    home.address = homeAddress;
    homes.push(home); 
    populated = await homeRegistry.exists(homes[0].getIdentifier());
    break;
default:
    throw new Error("No test transaction specified in module.init"); 
}

try {
    // Conditionally add/update registries

    if (!populated) {
        logger.debug('Adding test assets ...');
        await homeRegistry.addAll(homes);
        await ownerRegistry.addAll(owners);
        await deviceRegistry.addAll(devices);
        logger.debug('Asset addition complete ...');
    } else {
        logger.debug('Updating test assets ...');
        await removeExisting(homeRegistry, 'HOME_' + uuid);
        await removeExisting(ownerRegistry, 'OWNER_' + uuid);
        await removeExisting(deviceRegistry, 'DEVICE_' + uuid);
        await homeRegistry.addAll(homes);
        await ownerRegistry.addAll(owners);
        await deviceRegistry.addAll(devices);
        logger.debug('Asset update complete ...');
    }
} catch (error) {
    logger.error('error in test init(): ', error);
    return Promise.reject(error);
}

};

module.exports.run = function() { let transaction; switch(testTransaction){ case 'DeviceReading': { transaction = factory.newTransaction(namespace, 'DeviceReading'); transaction.device = factory.newRelationship(namespace, 'Device', 'DEVICE' + uuid + '' + assetId++); transaction.temperature = 40.0; let now = new Date(); now.setDate(now.getDate()); transaction.readingDate = now; transaction.readingTime = "12:00"; break; } case 'addingHome': { transaction = factory.newTransaction(namespace, 'AddingHome'); transaction.home = factory.newRelationship(namespace, 'Home', 'HOME'+uuid+''); break; } default: { throw new Error("No valid test transaction specified in module.run"); } }

return bc.bcObj.submitTransaction(busNetConnection, transaction);

};

module.exports.end = function() { return Promise.resolve(true); };



4. im using the fabric1.1/2org1peercouchdb setup i have also tried fabric1.2/2org1peercouchdb, and also both the goleveldb folders
5. the only difference from the standard docker setup, is that i have 1 org and 4 peers. One of them being the orderer

## Existing issues
<!-- Have you searched for any existing issues or are their any similar issues that you've found? -->
- [ ] [Stack Overflow issues](http://stackoverflow.com/tags/hyperledger-caliper)
- [ ] [GitHub Issues](https://github.com/hyperledger/caliper/issues)
- [ ] [Rocket Chat history](https://chat.hyperledger.org/channel/caliper)

<!-- please include any links to issues here -->

## Context
<!--- How has this bug affected you? What were you trying to accomplish? -->

## Your Environment
<!--- Include as many relevant details about the environment you experienced the bug in -->
* Version used:
* Environment name and version (e.g. Chrome 39, node.js 5.4): node 8.9.4 and fabric 1.1.0
* Operating System and version (desktop or mobile): ubuntu 18.4
* Link to your project:
aklenik commented 5 years ago

@Salmanah Please either share the above files as GitHub gists, or properly format them with the triple backtick notation so it's more readable.

ghost commented 5 years ago

@Salmanah Please either share the above files as GitHub gists, or properly format them with the triple backtick notation so it's more readable.

My aplogies, I have fixed it now.

aklenik commented 5 years ago

@Salmanah Hmm, can you check the local Caliper logs (in the log/ dir if you didn't change it)? From Caliper's POV, the benchmark is run successfully. You should also add some logging to your logic.js to see what happens inside.

ghost commented 5 years ago

@aklenik I checked the local Caliper logs and added some lines where I could see that my participants were created and if the transaction is called. Everything seems to be fine, but I noticed when I wrote a console.log in my logic.js nothing seems to be printed out, I do not think that the transaction is being called. What could be the reason for that?

ghost commented 5 years ago

@aklenik I just recently found a new error from one of the peer containers. This error is just running on my chaincode, which I think is weird. The other sample chaincodes do no generate an error when run under the same environment. newest_error

aklenik commented 5 years ago

@nklincoln Any pointers about how to activate the identity for a custom example?

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

iceboy220 commented 3 years ago

Hi every one I have the same problem. when my code send data to registry, all of the that be failed . can you help me(url). Untitled