Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added End-To-End Test for Datasource Hot-Reload #2453

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

RubenCerna2079
Copy link
Contributor

@RubenCerna2079 RubenCerna2079 commented Nov 7, 2024

Why make this change?

This change solves the issue #1866

What is this change?

Added an end-to-end test to ensure that DAB hot-reloads appropriately when there is a connection change from one database to another database (e.g. MSSQL to PostgreSQL).
In order to make tests related to hot reload less flaky, we stopped using the sleep() function and added an event in FileSystemRuntimeConfigLoader, which triggers when hot reload is complete. This event is used by the tests in order to wait until hot reload finishes.

How was this tested?

  • Integration Tests
  • Unit Tests

@RubenCerna2079
Copy link
Contributor Author

/azp run

@RubenCerna2079 RubenCerna2079 self-assigned this Nov 7, 2024
@RubenCerna2079 RubenCerna2079 added this to the 1.3 milestone Nov 7, 2024
GenerateConfigFile(
databaseType: expectedDatabaseType,
connectionString: expectedConnectionString);
System.Threading.Thread.Sleep(3000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a timer here, why dont we check for the existence of the new file, and wait until the new file is generated? Adding timer to the test makes it flaky.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file is already created beforehand and we are only updating the file.
We use a timer in order to ensure that the server has enough time to hot-reload before moving on with the rest of the testing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why you are using timer, but what if the update doesnt happen within 3 sec? can we instead check for the condition you expect to be true after the expiry of the timer instead of using a timer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, DAB is not able to work on any requests until hot-reload is finished. If that is the case, by having a request with await then the test should wait until the request and hot-reload are completed.
(Please correct me if I am wrong on that)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RubenCerna2079 , what happens if we don't add a sleep, does it fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhishekkumams, yes, since it does not give enough time for the hot-reload to take place

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an event that triggers when hot reload is completed.
This will be used in the tests to make them wait until hot reload finishes, before continuing with the tests.

Copy link
Contributor

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to avoid usage of timer

@RubenCerna2079
Copy link
Contributor Author

/azp run

// Assert
Assert.AreNotEqual(previousDatabaseType, actualDatabaseType);
Assert.AreEqual(expectedDatabaseType, actualDatabaseType);
SqlTestHelper.PerformTestEqualJsonStrings(_bookDBOContents, reloadGQLContents.GetProperty("items").ToString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_bookDBOContents has values from MSSQL, currently all the DBs have the same values, so we don't know if it actually picked the value from MSSQL or the updated DB. Would you be able to add one row to each db with different values which we can use for more robust testing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also Based on how our pipelines work, we do not support cross database access in single pipeline. But you can add another test which i mentioned in this issue itself.

@abhishekkumams
Copy link
Contributor

Can you also add one more test where you update the connection string with invalid value and then change it to a valid value, with 200 response?

@RubenCerna2079
Copy link
Contributor Author

Can you also add one more test where you update the connection string with invalid value and then change it to a valid value, with 200 response?

I don't think we need this test, since the hot-reload has a last known good config file to go to when there is an error, so it will not change anything by trying to change the connection string to an invalid value. And a successful connection string change is already tested with the current test that I am working on.

@RubenCerna2079
Copy link
Contributor Author

/azp run

@RubenCerna2079
Copy link
Contributor Author

/azp run

@RubenCerna2079
Copy link
Contributor Author

/azp run

@RubenCerna2079
Copy link
Contributor Author

/azp run

@RubenCerna2079
Copy link
Contributor Author

/azp run

@RubenCerna2079
Copy link
Contributor Author

/azp run

@RubenCerna2079
Copy link
Contributor Author

/azp run

@RubenCerna2079
Copy link
Contributor Author

/azp run

@RubenCerna2079
Copy link
Contributor Author

/azp run

@RubenCerna2079
Copy link
Contributor Author

/azp run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add end to end integration testing for hot reload of data source in config
3 participants