A test environment is generated when you create an EdgeRoutine (ER). The test environment allows you to simulate the configurations of the production environment, debug the code, and retest the code of previous versions. Because the test environment is isolated from the production environment (the business environment), operations performed in the test environment do not affect your business. After you test your ER in the test environment, you can publish the ER to the production environment.

Configure the test environment

The test environment can simulate the configurations of the production environment and the canary release environment, but it is isolated from the production environment and the canary release environment. We recommend that you modify the configuration of the test environment and fully test services in the test environment before you modify the configurations of the production environment and canary release environment to minimize potential risks.

  1. Log on to the DCDN console.
  2. In the left-side navigation pane, choose EdgeRoutine.
  3. Select a routine name and click Details.
  4. Select Settings and click Modify in the Test Environment section. You can configure Routine Specification and Domain Name Whitelist. Production
    Parameter Description
    Routine specification
    • CPU time slice for individual requests: 5 ms, maximum real time: 120s, memory: 128 MB.
    • CPU time slice for individual requests: 50 ms, maximum real time: 120s, memory: 128 MB.
    • CPU time slice for individual requests: 100 ms, maximum real time: 120s, memory: 128 MB.
    Note The fees vary based on routine specifications. For more information, see Billing.
    Domain name whitelist The list of domain names that can be associated with the ER. For example, if you set example.com, only requests from example.com can trigger the routine. Requests from other domain names are rejected by the routine. By default, the Domain Name Whitelist is empty. Requests from all domain names can be associated with the routine. Wildcard domains are supported.
  5. Click OK.

Debug code

  1. Log on to the Alibaba Cloud CDN console/DCDN console.
  2. In the left-side navigation pane, choose EdgeRoutine.
  3. Select a routine name and click Details.
  4. On the Details page, click Code.
  5. After you complete coding, click Save and Publish to Test Environment. Publish
  6. Add the IP address of the test environment provided on the Save and Publish to Test Environment page to the local hosts file. Then, you can use the domain name to access the test environment and test the code.
    Note Add the following content to the hosts file:
    • IP address: replace the IP address with one of the IP addresses displayed in Step 5.
    • Domain name: the CDN or DCDN domain name that is associated with the routine. For more information, see Associate domain names with a routine.
    Example: 42.123.119.45 example.com.

Test the code of a previous version

You can use the test environment to retest the code of a previous version. For example, you want to roll the production environment back to a previous version, but you are unsure whether the code of the previous version has errors. You can publish the previous version to the test environment. After you test the code, you can roll the production environment back to the previous version.

  1. Log on to the DCDN console.
  2. In the left-side navigation pane, choose EdgeRoutine.
  3. Select a routine name and click Details.
  4. On the Details page, click Versions.
  5. On the Versions page, you can publish a previous version to the test environment for testing.