From f710767f5611dbf9b23233c921fc6536c1802456 Mon Sep 17 00:00:00 2001 From: weekens Date: Tue, 15 Dec 2020 21:41:52 +0300 Subject: [PATCH 1/2] Added reproducing test for #50. --- test/typescript/test-hot-config-change.ts | 38 ++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/test/typescript/test-hot-config-change.ts b/test/typescript/test-hot-config-change.ts index cb4ae71..9169ca9 100644 --- a/test/typescript/test-hot-config-change.ts +++ b/test/typescript/test-hot-config-change.ts @@ -9,7 +9,7 @@ import * as actors from '../../'; import {expect} from 'chai'; -import {Actor, ActorRef, ActorSystem} from '../../index'; +import { Actor, ActorDefinition, ActorRef, ActorSystem } from '../../index'; import {afterEach, beforeEach} from 'mocha'; import * as common from '../../lib/utils/common'; import _ = require('underscore'); @@ -194,6 +194,42 @@ describe('Hot configuration change', () => { expect(finalPid).to.be.not.equal(pid2); expect(finalPid).to.be.not.equal(pid3); }); + + it('should respect custom parameters', async () => { + class TestActor implements ActorDefinition { + private selfActor: Actor; + + initialize(selfActor: Actor): void { + this.selfActor = selfActor; + } + + test() { + return `${this.selfActor.getCustomParameters().greeting} ${process.pid}`; + } + + destroy(): void { + // Nothing to do. + } + } + + let testActor = await rootActor.createChild(TestActor, { + mode: 'in-memory', + customParameters: { + greeting: 'Hello!' + } + }); + + let message = await testActor.sendAndReceive('test'); + + expect(message).to.match(/Hello! \d+/); + + await testActor.changeConfiguration({ mode: 'forked' }); + + let forkedMessage = await testActor.sendAndReceive('test'); + + expect(forkedMessage).to.match(/Hello! \d+/); + expect(forkedMessage).to.be.not.equal(message); + }); }); describe('changeGlobalConfiguration()', () => { From 1d2c48ab3d892535b286a8115b5e800bcd5b7de7 Mon Sep 17 00:00:00 2001 From: weekens Date: Tue, 15 Dec 2020 21:44:49 +0300 Subject: [PATCH 2/2] Fix missing custom parameters for hot config change. --- lib/actor.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/actor.js b/lib/actor.js index 087f8dd..7c9be3f 100644 --- a/lib/actor.js +++ b/lib/actor.js @@ -76,7 +76,7 @@ class Actor extends EventEmitter { createChild(definition, config) { if (this.getState() != 'new' && this.getState() != 'ready') return this._notReadyErrorPromise(); - + let log = this.getLog(); let childPromise = this.system.createActor(definition, this._parentReference(), config) .tap(actor => actor.initialize()) @@ -127,7 +127,7 @@ class Actor extends EventEmitter { let newActor = await this.system._createActor( this.origDefinition || this.definition, this.parent, - _.extend({ name: this.getName() }, config)); + _.extend({ name: this.getName(), customParameters: this.getCustomParameters() }, config)); await newActor.initialize(); await this.parent._augmentChild(this.getId(), newActor); @@ -318,7 +318,7 @@ class Actor extends EventEmitter { return this._overloadedErrorPromise(); let fwActor = this._checkForward(topic); - + if (fwActor) { if (this.getLog().isDebug()) { this.getLog().debug('Forwarding message to other actor, topic=', topic, @@ -436,7 +436,7 @@ class Actor extends EventEmitter { this._setState('destroying'); this.log.debug('Destroying...'); - + this.destroyPromise = P .map(this.childPromises, child => { return child.destroy() @@ -684,4 +684,4 @@ class Actor extends EventEmitter { } } -module.exports = Actor; \ No newline at end of file +module.exports = Actor;