telefonicaid / fiware-orion

Context Broker and CEF building block for context data management, providing NGSI interfaces.
https://github.com/telefonicaid/fiware-orion/blob/master/doc/manuals/orion-api.md
GNU Affero General Public License v3.0
210 stars 265 forks source link

Using static connection variable for DBClientConnection in all unit tests #51

Open LeandroGuillen opened 10 years ago

LeandroGuillen commented 10 years ago

In PR #232 we start using static variables for setting up database in this way:

  static DBClientConnection* connection = NULL;

  if (connection == NULL)
  {
    /* Set database */
    setupDatabase();

    connection = getMongoConnection();
  }

while most of the *_test.cpp files use:

  /* Set database */
  setupDatabase();

  DBClientConnection* connection = getMongoConnection();

This is @kzangeli comment about this in a later email:

A static variable in a function is like a global variable that is visible in one function only. The initial assignment of this static variable is made by the compiler, not in runtime. So, the first time the function is called, connection has the value of NULL. If its value is changed, that new value will be seen in consequent calls of the function.

Now, this function 'prepareDatabase' can be called several times but 'setupDatabase'

Thus, it seems to be smarter to use static variables for all *_test.cpp using database setup. This issue is about that global change.

Effort: 10 man day

fgalan commented 9 years ago

Currently, we are using a connection pool to the database (see current implementation of setupDatabase() for unit tests). Is this issue still making sense or should be closed?