Skip to content

Latest commit

 

History

History
155 lines (106 loc) · 5.88 KB

functional-tests.md

File metadata and controls

155 lines (106 loc) · 5.88 KB

Functional tests

Main language: Groovy. Project functional tests use Spock as a main testing framework. Also used Docker for running PBS and other services. Testcontainers is used as provider of lightweight, throwaway instances of PBS, MySQLContainer, MockServerContainer containers. And MockServer for mocking external services.

Getting Started

  • Install Docker
  • Set launchContainers system property to 'true'

Preparing the PBS Image

To prepare the PBS image, follow these steps from the root directory:

  1. Build the project using Maven:

mvn clean -B package -f extra/pom.xml

  1. Build the image:

2.1 Build image without modules:

mvn docker:build -f pom.xml

2.2 Build image with modules:

mvn docker:build -f pom.xml -DdockerfileName=Dockerfile-modules

Note: Don't forget to rebuild the image for manual test start after making changes in the dev code.

Running Functional Tests

You have two options for running functional tests:

  1. Use mvn verify to include all previous steps (including Java tests and modular tests) because Groovy runs in the failsafe:integration-test phase.
  2. For functional tests only, use a more granular command:

mvn -B verify -DskipModuleFunctionalTests=true

Running Module Functional Tests

You have two options for running modular tests:

  1. Use mvn verify -DdockerfileName=Dockerfile-modules to include all previous steps (including Java tests and functional tests) because Groovy runs in the failsafe:integration-test phase.
  2. For modular tests only, use a more granular command:

mvn -B verify -DskipUnitTests=true -DskipFunctionalTests=true -DskipModuleFunctionalTests=false -DdockerfileName=Dockerfile-modules

Developing

Functional tests need to have name template .*Spec.groovy

  • /functional/*Spec - contain all test suites.
  • /functional/util - different useful methods and wrappers.
  • /functional/repository - interaction with DB. Notice, that some related objects need to use ID generated by DB. Primary Key will be inserted after saving instance into DB.
  • /functional/service/PrebidServerService - responsible for all PBS http calls.
  • /functional/testcontainers/Dependencies - stores dependencies and manages mySql and NetworkServiceContainer containers.
  • /functional/testcontainers/ErrorListener - logs request and response in case of falling test.
  • /functional/testcontainers/PbsConfig - collects PBS properties.
  • /functional/testcontainers/PbsServiceFactory - manage PBS containers according to container limit.
  • /functional/testcontainers/PBSTestExtension - allows to hook into a spec’s lifecycle to add ErrorListener using annotation PBSTest.
  • /functional/testcontainers/TestcontainersExtension - allow to hook into a spec’s lifecycle to start and stop support service containers using global extension.
  • /functional/testcontainers/container - responsible for creating and configuring containers.
  • /functional/testcontainers/scaffolding/NetworkScaffolding - makes HTTP requests to a MockServer.

Properties:

launchContainers - responsible for starting the MockServer and the MySQLContainer container. Default value is false to not launch containers for unit tests. tests.max-container-count - maximum number of simultaneously running PBS containers. Default value is 2. skipFunctionalTests - allow to skip funtional tests. Default value is false. skipUnitTests - allow to skip unit tests. Default value is false.

Debug:

An application running inside a Docker container is treated as a remote application, so you can attach the debugger to it.

In order to obtain the debug port you need to use <tests.fixed-container-ports> property in pom to true by default false. Next several ports will expose when <tests.fixed-container-ports> is true.

  • Debug port is 8000 but can be overridden by <debug.port> in pom.
  • Admin port is 8060 but can be overridden by <admin.port> in pom.
  • Default port is 8080 but can be overridden by <port> in pom.
  • Prometheus port is 8070 but can't be overridden in pom. If needed can change in PrebidServerContainer constant PROMETHEUS_PORT.

Containers

Every container expose random port which you can see docker ps - running containers. (add flag -a to see exited containers)

You can observe logs inside container docker logs <container_id>. (You don't need to write all id, just use 2-3 symbols)

NetworkServiceContainer

Container for mocking different calls from PBS: prebid cache, bidders, currency conversion service, PubStack analytics, http data source

/auction - default mocked bidder call returns response based on information from request:

{
   "id":"0a00b9a1-06c0-4001-9d64-b6a3f7d995e6",
   "seatbid":[
      {
         "bid":[
            {
               "id":"c550cf25-3a09-480b-852f-e75a009bbefd",
               "impid":"b9a2756a-6aef-438c-85ed-53331a7b4c53",
               "price":1.23,
               "crid":"1"
            }
         ]
      }
   ]
}

/cache - mocked PBC call returns:

{
   "responses":[
      {
         "uuid":"8565b07a-8a64-476b-ac68-cc09b4560625"
      }
   ]
}

MySQLContainer

Container for Mysql database.

  • Use org/prebid/server/functional/db_mysql_schema.sql script for scheme.
  • DataBase: prebid
  • Username: prebid
  • Password: prebid

PostgreSQLContainer

Container for PostgreSQL database.

  • Use org/prebid/server/functional/db_psql_schema.sql script for scheme.
  • DataBase: prebid
  • Username: prebid
  • Password: prebid

PrebidServerContainer

Starting image prebid/prebid-server:latest. Waits for container is ready by checking "/status" endpoint.

TestContainer library

TestContainer will start special Ryuk container which will manage a lifecycle of all depending containers.