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

Routes with autoAliases not considered for started #347

Open
MichaelErmer opened this issue Jan 8, 2024 · 1 comment
Open

Routes with autoAliases not considered for started #347

MichaelErmer opened this issue Jan 8, 2024 · 1 comment

Comments

@MichaelErmer
Copy link
Contributor

MichaelErmer commented Jan 8, 2024

If a API gateway has a configuration using autoAliases, the service will be marker as "ready" (started) even if the routes are not registered yet:

name: "xyz",
routes: [{
    path: "/download",
    use: [cookieparser()],
    whitelist: ["xyz.download"],
    autoAliases: true,
    mappingPolicy: "restrict",
    logging: false,
}]
...
actions: {
    xyz: {
        rest: {
            method: "POST",
            path: "/"
        },
       ...
    }
}

If this syntax is used, it works as intended:

name: "xyz",
routes: [{
    path: "/download",
    use: [cookieparser()],
    whitelist: ["xyz.download"],
    aliases: {
        "POST /": "xyz.download"
    }
    mappingPolicy: "restrict",
    logging: false,
}]
...
actions: {
    download: {
        rest: {
            method: "POST",
            path: "/"
        },
       ...
    }
}

this test will randomly fail for the first case:

describe("test", () => {
    beforeAll(async () => {
        broker.createService(xyzService);
        await broker.start();
        await broker.waitForServices(["xyz"]);
    });
    // test to request /download
});
@icebob
Copy link
Member

icebob commented Jan 13, 2024

This is the expected functionality. The reason is, that the auto aliases function executes with a little delay to wait for all services should be started. In the case of a monolith, it looks like no reason to wait, but in a multi-node environment, if API gateway started, it doesn't mean all other services are loaded.

For tests, you should add a delay after the broker started, or set the debounceTime to zero in API gateway settings.

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

No branches or pull requests

2 participants