From a5ddbe8d39d46e71c949a37e4dccbc7d4a342ac9 Mon Sep 17 00:00:00 2001 From: ryMarsh44 Date: Tue, 10 Oct 2017 09:44:55 -0600 Subject: [PATCH] Refactored tests and removed list_state references (#22) * When node's garbage collection is triggered, a callback in clearOnExit will be called which calls release on the Rust connection object. Garbage collection should happen with our sdk when garbage collection happens with node. Improved Tests * added comments for the clearOnExit * Removed the list_state function in connection object because it isn't implemented in Rust yet. * fixed connection tests and Connection Interface * changed vars to camel case. Changed docker file to update npm * deleted js files in src directory * changed test because of naming conflicts * fixed path for one of the imports * changed tsconfig * added dist directory. This will be temporary * added weak library to package.json * Corrected the test format for index-test.js Removed the references to cxs_connection_list_state because we aren't using it yet Fixed paths in connection-test * added js files from dist. Won't have in the future * Removed the dist directory from github Signed-off-by: ryMarsh44 --- cxs/wrappers/node/src/api/connection.ts | 4 +- cxs/wrappers/node/src/rustlib.ts | 6 +- cxs/wrappers/node/test/connection-test.js | 15 ++--- cxs/wrappers/node/test/index-test.js | 70 +++++------------------ cxs/wrappers/node/tsconfig.json | 24 ++++---- 5 files changed, 35 insertions(+), 84 deletions(-) diff --git a/cxs/wrappers/node/src/api/connection.ts b/cxs/wrappers/node/src/api/connection.ts index 9c152664b6..c47c3364e1 100644 --- a/cxs/wrappers/node/src/api/connection.ts +++ b/cxs/wrappers/node/src/api/connection.ts @@ -1,9 +1,8 @@ import * as ffi from 'ffi' import * as ref from 'ref' -import * as Struct from 'ref-struct' import * as weak from 'weak' import { CXSRuntime } from '../index' -import { CXSRuntimeConfig, CxsStatus, FFI_CXS_STATUS_PTR } from '../rustlib' +import { CXSRuntimeConfig } from '../rustlib' import { IConnections @@ -12,7 +11,6 @@ import { export class Connection implements IConnections { public connectionHandle: ref.types.uint32 public state: ref.types.uint32 - public statusList: any private RUST_API: ffi constructor ( path?: string ) { diff --git a/cxs/wrappers/node/src/rustlib.ts b/cxs/wrappers/node/src/rustlib.ts index 91f3e34213..93417ab0f6 100644 --- a/cxs/wrappers/node/src/rustlib.ts +++ b/cxs/wrappers/node/src/rustlib.ts @@ -16,9 +16,9 @@ export const FFI_CONNECTION_HANDLE = 'uint32' export const FFI_UNSIGNED_INT = 'uint32' export const FFI_UNSIGNED_INT_PTR = ref.refType('uint32') export const FFI_STRING = 'string' +export const FFI_CONFIG_PATH = FFI_STRING export const FFI_STRING_DATA = 'string' export const FFI_CONNECTION_HANDLE_PTR = ref.refType(FFI_CONNECTION_HANDLE) -export const FFI_CXS_STATUS_PTR = ref.refType(CxsStatus) // Rust Lib Native Types export type rust_did = string @@ -48,9 +48,7 @@ export const FFIConfiguration = { cxs_connection_create: [FFI_ERROR_CODE, [FFI_STRING_DATA, FFI_CONNECTION_HANDLE_PTR]], cxs_connection_get_data: [FFI_STRING_DATA, [FFI_CONNECTION_HANDLE]], cxs_connection_get_state: [FFI_ERROR_CODE, [FFI_CONNECTION_HANDLE, FFI_UNSIGNED_INT_PTR]], - cxs_connection_list_state: [FFI_ERROR_CODE, [FFI_CXS_STATUS_PTR]], cxs_connection_release: [FFI_ERROR_CODE, [FFI_CONNECTION_HANDLE]], - cxs_init: ['int', ['string']] - + cxs_init: [FFI_ERROR_CODE, [FFI_CONFIG_PATH]] } diff --git a/cxs/wrappers/node/test/connection-test.js b/cxs/wrappers/node/test/connection-test.js index dfe016519c..ecb1813685 100644 --- a/cxs/wrappers/node/test/connection-test.js +++ b/cxs/wrappers/node/test/connection-test.js @@ -1,7 +1,4 @@ var chai = require('chai'); -var fs = require('fs-extra'); -var ref = require('ref') -var Struct = require('ref-struct') var parentDir = require('path'); var currentDir = parentDir.dirname(module.filename); var Connection = require(parentDir.dirname(currentDir) + '/dist/api/connection').Connection @@ -51,19 +48,19 @@ describe('A Connection object with ', function () { connection.create("dog, cat, man") var data = connection.getData() var jsonData = JSON.parse(data) - assert.notEqual(data, "") + assert.notEqual(data, null) assert.equal(jsonData.handle, connection.connectionHandle) }) - it('a call to get_data where connection doesnt exist should return an empty string', function () { + it('a call to get_data where connection doesnt exist should return a null value', function () { assert.equal(connection.getData(), null) }) - it('a call to get_data where connection with connection released should return an empty string', function () { + it('a call to get_data where connection was released should return a null value', function () { connection.create("info") assert.equal(connection.connect(), 0) var data = connection.getData() - assert.notEqual(data, "") + assert.notEqual(data, null) assert.equal(connection.release(), 0) data = connection.getData() assert.equal(data, null) @@ -117,13 +114,13 @@ describe('A Connection object with ', function () { return predicate() } - it('connection and GC deletes object should return empty whet get_data is called ', function () { + it('connection and GC deletes object should return null whet get_data is called ', function () { const connection = new Connection(path) connection.create("msg") connection.connect() const getData = connection.RUST_API.cxs_connection_get_data const handle = connection.connectionHandle - assert.notEqual(connection.getData(handle), "") + assert.notEqual(connection.getData(handle), null) this.timeout(30000) delete connection diff --git a/cxs/wrappers/node/test/index-test.js b/cxs/wrappers/node/test/index-test.js index bad4de8bd4..9309546b57 100644 --- a/cxs/wrappers/node/test/index-test.js +++ b/cxs/wrappers/node/test/index-test.js @@ -1,14 +1,13 @@ require('chai'); require('fs-extra'); -var index = require('../dist/index'); -var rustlib = require('../dist/rustlib'); -var assert = require('assert'); var parentDir = require('path'); +var currentDir = parentDir.dirname(module.filename); +var index = require(parentDir.dirname(currentDir) + '/dist/index') +var rustlib = require(parentDir.dirname(currentDir) + '/dist/rustlib') +var assert = require('assert'); var CXSRuntime = index.CXSRuntime; var CXSRuntimeConfig = rustlib.CXSRuntimeConfig; -var currentDir = parentDir.dirname(module.filename); var ref = require('ref') -var Struct = require('ref-struct') describe('call to cxs_init with provided path', function() { @@ -24,74 +23,33 @@ describe('call to cxs_init with provided path', function() { }) }); +// these tests were created to only test that the ffi could be called with each function -describe('call to cxs_connection_create ', function() { +describe('Using the cxs ffi directly ', function() { var path = parentDir.dirname(currentDir); path += "/lib/libcxs.so"; var run = new CXSRuntime(new CXSRuntimeConfig(path)); - var intPtr = ref.alloc('int') - it('should return 0', function () { + + it('a call to cxs_connection_create should return 0', function () { + var intPtr = ref.alloc('int') assert.equal(run.ffi.cxs_connection_create("dog, cat, man", intPtr), 0) }) -}); -describe('call to cxs_connection_connect without the ability to connect', function() { - var path = parentDir.dirname(currentDir); - path += "/lib/libcxs.so"; - var run = new CXSRuntime(new CXSRuntimeConfig(path)); - it('should return 1', function () { + it('a to cxs_connection_connect without the ability to connect should return 1', function () { assert.equal(run.ffi.cxs_connection_connect(2), 1001) }) -}); -describe('call to cxs_connection_get_data ', function() { - var path = parentDir.dirname(currentDir); - path += "/lib/libcxs.so"; - var run = new CXSRuntime(new CXSRuntimeConfig(path)); - it('should return 0', function () { + it('a call to cxs_connection_get_data should return 0', function () { assert.equal(run.ffi.cxs_connection_get_data(2), null) }) -}); -describe('call to cxs_connection_get_state ', function() { - var path = parentDir.dirname(currentDir); - path += "/lib/libcxs.so"; - var run = new CXSRuntime(new CXSRuntimeConfig(path)); - it('should return 0', function () { + it('a call to cxs_connection_get_state should return 0', function () { var intPtr = ref.alloc('int') assert.equal(run.ffi.cxs_connection_get_state(2, intPtr), 0) }) -}); -describe('call to cxs_connection_release without ability to release ', function() { - var path = parentDir.dirname(currentDir); - path += "/lib/libcxs.so"; - var run = new CXSRuntime(new CXSRuntimeConfig(path)); - it('should return 1', function () { + it('a call to cxs_connection_release without ability to release should return 1', function() { assert.equal(run.ffi.cxs_connection_release(2), 1001) }) -}); -// var CxsStatus = Struct({ -// 'handle': 'int', -// 'status': 'int', -// 'msg': 'string' -// }); -// -// var cxsStruct = new CxsStatus({ -// 'handle': 8, -// 'status': 9, -// 'msg': "StringMSG" -// }); - - -// describe('call to cxs_connection_list_state ', function() { -// var path = parentDir.dirname(currentDir); -// path += "/lib/libcxs.so"; -// var run = new CXSRuntime(new CXSRuntimeConfig(path)); -// var structPtr = ref.alloc(cxsStruct) -// -// it('should return 0', function () { -// assert.equal(run.ffi.cxs_connection_list_state(structPtr), 0) -// }) -// }); +}); diff --git a/cxs/wrappers/node/tsconfig.json b/cxs/wrappers/node/tsconfig.json index 707e31b9dc..94fd988c8e 100644 --- a/cxs/wrappers/node/tsconfig.json +++ b/cxs/wrappers/node/tsconfig.json @@ -1,14 +1,14 @@ { - "compilerOptions": { - "target": "es2016", - "module": "commonjs", - "sourceMap": true, - "outDir": "./dist" - }, - "include": [ - "src/**/*" - ], - "exclude": [ - "node_modules" - ] + "compilerOptions": { + "target": "es2016", + "module": "commonjs", + "sourceMap": true, + "outDir": "./dist" + }, + "include": [ + "src/**/*" + ], + "exclude": [ + "node_modules" + ] }