Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove obsolete v1 tests #248

Merged
merged 5 commits into from
Jul 15, 2021
Merged

Remove obsolete v1 tests #248

merged 5 commits into from
Jul 15, 2021

Conversation

jason-fox
Copy link
Contributor

  • These tests are duplicated by equivalent v2 tests

In order to merge telefonicaid/iotagent-node-lib#995 I want to get the unit-tests running without relying on NGSI-v1. This PR just deletes tests which are already duplicated in the NGSI-v2 test suite. Any drop in coverage should be within acceptable limits.

- These tests are duplicated by equivalent v2 tests
@fgalan
Copy link
Member

fgalan commented Apr 13, 2021

Maybe this PR shoud use jason-fox:feature/ngsi-v1 as dependency for iotagent-node-lib in packages.json so we can use it at the same time to check that the new version of the library will work fine with the agent?

@jason-fox
Copy link
Contributor Author

Maybe this PR should use jason-fox:feature/ngsi-v1 as dependency for iotagent-node-lib in packages.json so we can use it at the same time to check that the new version of the library will work fine with the agent?

Eventually it will, but some of the unit-tests which are still v1, which haven't got v2 duplicates will need to updated to use first. This series of PR is just reducing the target area by deleting obvious duplicates first.

@fgalan
Copy link
Member

fgalan commented Apr 13, 2021

GitHub Actions is reporting this fail in tests:

  20 passing (17s)
  4 pending
  1 failing

  1) Command attributes test
       When a command value is changed in Orion for a preprovisioned device
         "before each" hook for "should send the execution command to the LWM2M client":
     Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/runner/work/lightweightm2m-iotagent/lightweightm2m-iotagent/test/unit/ngsiv2/commands-test.js)

Sometimes we have glitches due to timeout expiration in tests, but not sure if this is the case. I have re-run GitActions several times and it seems it always fail the same way.

Currently master is fine:

imagen

I'll relaunch test in master. Let's see how it goes...

@fgalan
Copy link
Member

fgalan commented Apr 13, 2021

The run in master has failed:

imagen

However, not the same way... much more test are failing in master:

  36 passing (31s)
  8 pending
  12 failing

Not sure what could be happening (maybe some recent changes in iotagent-node-lib that have impacted someway in this agent?) but until this can be analyzed in master I think it is not good idea to merge this PR... it would increase entropy in the code.

@jason-fox
Copy link
Contributor Author

@mapedraza @fgalan - given the recent activity on other PRs, I think this may be ready too. It is a simple deletion. I don't know why the one test is timing out, but it is better than existing master

Comment on lines -213 to -285
describe(
'When a device sends a registration request for a provisioned device without type configuration' +
' and without an explicit LWM2M Mapping',
function(done) {
const registration = {
url: 'http://localhost:' + config.ngsi.server.port + '/iot/devices',
method: 'POST',
json: utils.readExampleFile('./test/provisionExamples/provisionMinimumDevice.json'),
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
}
};

beforeEach(function(done) {
async.series(
[
apply(lwm2mClient.registry.create, '/3303/0'),
apply(lwm2mClient.registry.create, '/3304/0'),
apply(lwm2mClient.registry.setResource, '/3303/0', '0', '19'),
apply(lwm2mClient.registry.setResource, '/3304/0', '0', '85'),
apply(request, registration),
apply(lwm2mClient.register, clientConfig.host, clientConfig.port, '/', 'ws1')
],
function(error) {
done();
}
);
});

it('should use the OMA Registry mapping to create the NGSI attributes', function(done) {
const ngsiQuery = {
url:
'http://' +
config.ngsi.contextBroker.host +
':' +
config.ngsi.contextBroker.port +
'/v1/queryContext',
method: 'POST',
json: {
entities: [
{
type: 'WeatherStation',
isPattern: 'false',
id: 'Weather1'
}
],
attributes: ['Temperature Sensor#0']
},
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
}
};

request(ngsiQuery, function(error, response, body) {
should.not.exist(error);
should.not.exist(body.orionError);
response.statusCode.should.equal(200);

should.exist(body.contextResponses);
should.exist(body.contextResponses[0]);
should.exist(body.contextResponses[0].contextElement);
should.exist(body.contextResponses[0].contextElement.attributes[0]);
should.exist(body.contextResponses[0].contextElement.attributes[0].value);
body.contextResponses[0].contextElement.attributes[0].value.should.equal('19');

done();
});
});
it('should support the unregistered attributes with a register in OMA Registry');
}
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This describe is not present on v2 test

Comment on lines -381 to -456
describe('When a preprovisioned device sends a registration request to the the IoT Agent', function(done) {
const options = {
url: 'http://localhost:' + config.ngsi.server.port + '/iot/devices',
method: 'POST',
json: utils.readExampleFile('./test/provisionExamples/preprovisionDevice.json'),
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
}
};

beforeEach(function(done) {
request(options, function(error, response, body) {
async.series(
[
apply(lwm2mClient.registry.create, '/5000/0'),
async.apply(lwm2mClient.registry.setResource, '/5000/0', '2', '89'),
async.apply(lwm2mClient.registry.setResource, '/5000/0', '2', '19')
],
done
);
});
});

it('should return the registration information', function(done) {
lwm2mClient.register(clientConfig.host, clientConfig.port, '/rd', 'PreprovisionedLight1', function(
error,
result
) {
should.not.exist(error);
should.exist(result);
should.exist(result.serverInfo);
should.exist(result.location);

done();
});
});
it('should register its passive attributes in the Context Broker as a Context Provider', function(done) {
lwm2mClient.register(clientConfig.host, clientConfig.port, '/rd', 'PreprovisionedLight1', function(
error,
result
) {
ngsiClient.discover('ThePreprovisionedLight', 'APreprovisionedDevice', undefined, function(
error,
response,
body
) {
should.not.exist(error);
should.exist(body);
should.not.exist(body.errorCode);
done();
});
});
});
it('should subscribe to its active attributes', function(done) {
lwm2mClient.register(clientConfig.host, clientConfig.port, '/rd', 'PreprovisionedLight1', function(
error,
result
) {
setTimeout(function() {
ngsiClient.query('ThePreprovisionedLight', 'APreprovisionedDevice', ['pressure'], function(
error,
response,
body
) {
should.not.exist(error);
should.exist(body);
should.not.exist(body.errorCode);
body.contextResponses[0].contextElement.attributes[0].value.should.match(/19|89/);

done();
});
}, 500);
});
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This describe is not present on v2 test

Comment on lines -494 to -527
it('should observe internal attributes', function(done) {
lwm2mClient.register(clientConfig.host, clientConfig.port, '/rd', 'ws1', function(error, result) {
should.not.exist(error);
should.exist(result);
should.exist(result.serverInfo);
should.exist(result.location);
setTimeout(function() {
async.series(
[
async.apply(lwm2mClient.registry.setResource, '/3303/0', '0', '89'),
async.nextTick,
async.apply(lwm2mClient.registry.setResource, '/3303/0', '0', '33'),
async.nextTick,
async.apply(lwm2mClient.registry.setResource, '/3303/0', '0', '19'),
async.nextTick
],
function(error) {
setTimeout(function() {
ngsiClient.query('weather1', 'weatherStation', ['Temperature Sensor'], function(
error,
response,
body
) {
should.not.exist(error);
should.exist(body);
should.not.exist(body.errorCode);
body.contextResponses[0].contextElement.attributes[0].value.should.equal('19');
done();
});
}, 500);
}
);
}, 1000);
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This it case is not present in v2 test

Comment on lines -1 to -178
apply(lwm2mClient.registry.create, '/3303/0'),
async.apply(lwm2mClient.registry.setResource, '/3303/0', '0', '19')
],
done
);
});

it('should return the appropiate error', function(done) {
const deviceInfo = {
_id: '5a5dfe44f3dffc5e233d27d3',
id: 79,
type: 'Device',
name: 'ws1',
lifetime: '85671',
path: '/rd/rd',
port: 35239,
address: '127.0.0.1',
creationDate: '2018-01-16T13:29:40.972Z'
};

updateRegistration.handler(deviceInfo, null, function(error) {
should.exist(error);
error.name.should.equal('DEVICE_NOT_FOUND');
done();
});
});
});

describe(
'When a preprovisioned device registers to the the IoT Agent with an active attribute ' +
'without internal mapping, but present in the OMA registry',
function(done) {
const options = {
url: 'http://localhost:' + config.ngsi.server.port + '/iot/devices',
method: 'POST',
json: utils.readExampleFile('./test/provisionExamples/preprovisionDeviceOMANoInternalMapping.json'),
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
}
};

beforeEach(function(done) {
request(options, function(error, response, body) {
async.series(
[
apply(lwm2mClient.registry.create, '/3303/0'),
async.apply(lwm2mClient.registry.setResource, '/3303/0', '0', '19')
],
done
);
});
});

it('should handle device update queries and restart observations', function(done) {
lwm2mClient.register(clientConfig.host, clientConfig.port, '/rd', 'ws1', function(error, result) {
should.not.exist(error);
should.exist(result);
should.exist(result.serverInfo);
should.exist(result.location);
lwm2mClient.update(result, function(error, result) {
should.not.exist(error);
should.exist(result);
should.exist(result.serverInfo);
should.exist(result.location);
setTimeout(function() {
async.series(
[
async.apply(lwm2mClient.registry.setResource, '/3303/0', '0', '44'),
async.nextTick,
async.apply(lwm2mClient.registry.setResource, '/3303/0', '0', '22'),
async.nextTick,
async.apply(lwm2mClient.registry.setResource, '/3303/0', '0', '00'),
async.nextTick
],
function(error) {
setTimeout(function() {
ngsiClient.query('weather1', 'weatherStation', ['Temperature Sensor'], function(
error,
response,
body
) {
should.not.exist(error);
should.exist(body);
should.not.exist(body.errorCode);
body.contextResponses[0].contextElement.attributes[0].value.should.equal(
'00'
);
done();
});
}, 500);
}
);
}, 1000);
});
});
});
}
);
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test does not have an equivalent in ngsiv2

@fgalan
Copy link
Member

fgalan commented Jul 15, 2021

Gaps detected by @mapedraza moved to issue #252

Copy link
Member

@fgalan fgalan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fgalan fgalan merged commit 233fef2 into telefonicaid:master Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants