Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

AzureFunctions: How to make a sync call to a QueueTrigger Function for an automated functional test

Let me introduce the scenario:

  1. I need to test an AzureFunction with a queue trigger:

    [FunctionName("AFunction")]
    public async Task DispatchAction([QueueTrigger("queuename")] string message)
    {
        await DoMyLogicAsync();
    }
    
  2. The test needs to be run by the "functional-test-container" in my docker-compose testing env, which is made up by:

    a) functional-test-container: a .net core container running an nUnit test suite

    b) azure-function-container: this container hosts the azure function

    c) azurite-container: this container hosts the queue server

    d) sql-server-container

    e) wiremock-container

The test logic is the following:

  1. Clear the sql database, the queue and wiremock status
  2. Prepare the wiremock stubs
  3. Somehow trigger the function
  4. wait for the function to end
  5. make assertions on what the function produced in sql server, in the queue and on what wiremock's stubs have been called

As far as I know I have 2 ways of triggering the function:

a) pushing a message in the queue

b) using azure function's admin API /admin/functions/afunction

the problem is that both of them don't give any hint on when the function ends its execution.

Here it is my question: is there a way to call the function in a "sync" way (so that I can know when the execution ends)?

question from:https://stackoverflow.com/questions/65642505/azurefunctions-how-to-make-a-sync-call-to-a-queuetrigger-function-for-an-automa

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I don't think it can be implemented. The queue trigger function runs as an instance in azure server, we can just trigger it to run. It doesn't response any data like HttpTrigger function. So it can't be executed synchronously in your entire process.

To solve your problem, I think you can just add some code to do an operation at the end of your function. The operation is used to let you know the function execution is completed. Or another solution is move the steps after function into your function code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...