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

async controller functions are not resolved #417

Closed
freakadunse opened this issue Feb 1, 2023 · 5 comments · Fixed by #423
Closed

async controller functions are not resolved #417

freakadunse opened this issue Feb 1, 2023 · 5 comments · Fixed by #423
Labels
bug Something isn't working

Comments

@freakadunse
Copy link

Describe the bug
Asynchronous functions in UI5 Controller are callable, but the promise will not be fulfilled.
The await of the promise results in a timeout.

To Reproduce
Create a UI5 application with only one view and create the following method in the controller:

    public async getBusinessPartners() {
        return this.query({ entitySet: '/BusinessPartnerSet' });
    }

Create a WDI5 Test suite with the following test:
This would result either in errors or unresolved promises or timeout.

        const selector = {
            selector: {
                controlType: "sap.ui.core.mvc.XMLView",
            }
        }
        const view = await (browser as any).asControl(selector);
        const controller = await view.getController();
        const businessPartners = await controller.getBusinessPartners();

Using sync controller functions will return the correct value.

Expected behavior
The Promise of the controller function would be resolved.

Runtime Env (please complete the following information):

  • wdi5/wdio-ui5-service-version: 1.1.0
  • UI5 version: 1.109.0
  • wdio-version (output of wdio --version): 7.30.0
  • node-version (output of node --version): v16.13.2
  • OS: Windows
  • Browser + Version: chrome 109.0
@vobu
Copy link
Contributor

vobu commented Feb 3, 2023

hi, as we're in Node.js land with wdi5, awaiting regular Promises should be no issue. Could you please elaborate on what this.query() does? Maybe a network issue/auth issue? Also, a minimal reproducible sample would work wonders here 😄

@dominikfeininger
Copy link
Collaborator

Maybe this line causes indeed the issue:

let result = oObject[methodName].apply(oObject, args)
further investigation is needed.

@freakadunse
Copy link
Author

@vobu
this.query() is an async function that promisifies the read/query operation of a odata call.
so ODatamodel.read('/EntitySet') for example.

But that doesn't really matter, as async functions in general might be an issue at least with me :D

Little example controller:

export default class App extends BaseController {
    public async onInit(): Promise<void> {
        console.log("App controller onInit");
    }

    public getSyncNumber(): number{
        return 10;
    }

    public async getAsyncNumber(): Promise<number> {
        return new Promise((resolve,reject) => {
            resolve(10);
        })
    }

    public async getBusinessPartners() {
        return this.query({ entitySet: '/BusinessPartnerSet' });
    }
}

and the corresponding test case:

describe("binding", () => {
    it("Odata create", async () => {
        const selector = {
            selector: {
                controlType: "sap.ui.core.mvc.XMLView",
            }
        }
        const view = await (browser as any).asControl(selector);
        const controller = await view.getController();

        console.log("sync number", await controller.getSyncNumber());

        const number = await controller.getAsyncNumber();
        console.log(number)
    })
})

This will result in the following messages/log:

[0-0] sync number 10
[0-0] WDI5Object {
[0-0]   _uuid: 'e5accab5-3ded-425f-895a-f6045584ecb3',
[0-0]   _aProtoFunctions: [
[0-0]     'then',
[0-0]     'catch',
[0-0]     'finally',
[0-0]     'hasOwnProperty',
[0-0]     'isPrototypeOf',
[0-0]     'propertyIsEnumerable',
[0-0]     'toString',
[0-0]     'valueOf',
[0-0]     'toLocaleString'
[0-0]   ],
[0-0]   _baseObject: {},
[0-0]   then: [Function: bound ],
[0-0]   catch: [Function: bound ],
[0-0]   finally: [Function: bound ],
[0-0]   hasOwnProperty: [Function: bound ],
[0-0]   isPrototypeOf: [Function: bound ],
[0-0]   propertyIsEnumerable: [Function: bound ],
[0-0]   toString: [Function: bound ],
[0-0]   valueOf: [Function: bound ],
[0-0]   toLocaleString: [Function: bound ]
[0-0] }

if i await for this promise like const number = await( await controller.getAsyncNumber() ); it will end in a timeout.

@vobu
Copy link
Contributor

vobu commented Feb 6, 2023

thanks for the additional context @freakadunse. your test/use case is very close to the unit testing scope, and not really in the e2e scope ("as a user would operate the app"). Still, here's what we'll do: put in a test case reflecting the setup and refactor so that also in the browser scope,wdi5 can await async controller calls. Might take a couple of days, but will happen 👍

@freakadunse
Copy link
Author

you are right @vobu, this is closer to unit testing. But what i test is a controller i extend for all view controllers which gives me methods for application handling like async query and reads, that i need with detail-view data collection on route navigations.
So this is a huge part in my application and would be used in e2e application tests also 🙂

but anyways: thanks for taking a look into it and providing a new version in the near future 😊

@vobu vobu added the bug Something isn't working label Feb 7, 2023
@vobu vobu closed this as completed in #423 Feb 8, 2023
vobu added a commit that referenced this issue Feb 8, 2023
* detect client async fn and await them
* cater towards throwing async fn client-side
fixes #417
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants