Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/threads/itc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const hdbUtils = require('../../utility/common_utils.js');
const hdbTerms = require('../../utility/hdbTerms.ts');
const { ITC_ERRORS } = require('../../utility/errors/commonErrors.js');
const { threadId, isMainThread } = require('worker_threads');

Check failure on line 6 in server/threads/itc.js

View workflow job for this annotation

GitHub Actions / runLinter

eslint(no-unused-vars)

Variable 'isMainThread' is declared but never used. Unused variables should start with a '_'.
const { onMessageFromWorkers, broadcastWithAcknowledgement } = require('./manageThreads.js');

module.exports = {
Expand Down Expand Up @@ -31,7 +31,7 @@
* @param event
*/
function sendItcEvent(event) {
if (!isMainThread && event.message) event.message.originator = threadId;
if (event.message) event.message.originator = threadId;
return broadcastWithAcknowledgement(event);
}

Expand Down
39 changes: 39 additions & 0 deletions unitTests/server/itc/utility/itcUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

const chai = require('chai');
const sinon = require('sinon');
const sinon_chai = require('sinon-chai').default;
const rewire = require('rewire');
chai.use(sinon_chai);
const { expect } = chai;
const hdb_logger = require('#js/utility/logging/harper_logger');
const itc_utils = require('#js/server/threads/itc');
Expand Down Expand Up @@ -44,6 +47,42 @@ describe('Test itcUtils module', () => {
});
});

describe('Test sendItcEvent function', () => {
let itc_rewired;
let broadcast_stub;

before(() => {
itc_rewired = rewire('#js/server/threads/itc');
broadcast_stub = sinon.stub().resolves();
itc_rewired.__set__('broadcastWithAcknowledgement', broadcast_stub);
});

afterEach(() => {
broadcast_stub.resetHistory();
});

it('sets originator on message when called from main thread', () => {
const event = { type: 'schema', message: { operation: 'create_schema' } };
itc_rewired.sendItcEvent(event);
expect(event.message.originator).to.not.equal(undefined);
expect(broadcast_stub).to.have.been.calledOnce;
});

it('sets originator to threadId regardless of isMainThread value', () => {
const event = { type: 'schema', message: { operation: 'create_schema' } };
const { threadId } = require('node:worker_threads');
itc_rewired.sendItcEvent(event);
expect(event.message.originator).to.equal(threadId);
});

it('does not set originator when message is absent', () => {
const event = { type: 'schema' };
itc_rewired.sendItcEvent(event);
expect(event.originator).to.equal(undefined);
expect(broadcast_stub).to.have.been.calledOnce;
});
});

describe('Test constructor functions', () => {
it('Test SchemaEventMsg', () => {
const expected_obj = {
Expand Down
4 changes: 2 additions & 2 deletions utility/environment/systemInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,8 @@ function getLMDBStats(table: Table, dbStats: DBStats): void {
const { root: _root, ...stats } = table.primaryStore.rootStore.getStats();
Object.assign(dbStats, stats);
dbStats.readers = table.primaryStore.rootStore
.readerList()
.split(/\n\s+/)
.readerList?.()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should only be called from the LMDB code path. Is it being called somehow from a RocksDB path?!

?.split(/\n\s+/)
.slice(1)
.map((line) => {
const [pid, thread, txnid] = line.trim().split(' ');
Expand Down
Loading