Search code examples
c#azureazure-functionsacceptance-testingspecrun

Acceptance testing functionality involving time-triggered azure function


My acceptance testing infrastructure uses specrun to create simulate a user, invoke my web service and check for results. This works well to test functionalities which involves user interactions (calling REST api, sending message etc).

But, in the backend I also have a functionality which involves a time-triggered Azure function which does some actions on certain azure blobs and sends a message to the user over an eventhub. How can I acceptance test functionality which involves this azure function ? - since this azure function is triggered only once every 6 hours, and not practical to run the acceptance test for a complete 6 hours to test this functionality.

Anybody has experience dealing which such a situation ? What would you suggest ?


Solution

  • While there is an admin API that the portal uses to invoke functions (and you can use it -- the browser's F12 tools can show you how it works), there are no promises that the API will remain the same going forward.

    Another approach may be to break down your functions to allow you to call into your "real" logic from either a timer or a test:

    1. Create a QueueTrigger function with your logic.
    2. Create a TimerTrigger that puts a message into the queue. This has the added benefit of failure retries, as well.
    3. Create your own HttpTrigger (protected with a key, by default) that you can invoke directly from your tests. Have this also stick a message into the queue.

    Alternatively, instead of having the QueueTrigger, you could have all of your logic implemented in a helper library and still expose the functions from #2 and #3 -- just have them be thin wrappers that call directly into the helper.