Skip to content

Commit

Permalink
Merge pull request #57 from untu/fix-config-change-custom-data
Browse files Browse the repository at this point in the history
Fix missing custom parameters for hot config change
  • Loading branch information
weekens authored Dec 15, 2020
2 parents a2c542b + 1d2c48a commit 110b8d4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -684,4 +684,4 @@ class Actor extends EventEmitter {
}
}

module.exports = Actor;
module.exports = Actor;
38 changes: 37 additions & 1 deletion test/typescript/test-hot-config-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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()', () => {
Expand Down

0 comments on commit 110b8d4

Please sign in to comment.