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

Fix refresh issue #802

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Member

Choose a reason for hiding this comment

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

We should also set refresh policy for delete action

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.opensearch.action.index.IndexRequest
import org.opensearch.action.index.IndexResponse
import org.opensearch.action.search.SearchRequest
import org.opensearch.action.search.SearchResponse
import org.opensearch.action.support.WriteRequest.RefreshPolicy
import org.opensearch.action.support.master.AcknowledgedResponse
import org.opensearch.client.Client
import org.opensearch.cluster.service.ClusterService
Expand Down Expand Up @@ -182,7 +183,7 @@ internal object NotificationConfigIndex : ConfigOperations {
*/
override suspend fun createNotificationConfig(configDoc: NotificationConfigDoc, id: String?): String? {
createIndex()
val indexRequest = IndexRequest(INDEX_NAME)
val indexRequest = IndexRequest(INDEX_NAME).setRefreshPolicy(RefreshPolicy.IMMEDIATE)
.source(configDoc.toXContent())
.create(true)
if (id != null) {
Expand Down Expand Up @@ -291,7 +292,7 @@ internal object NotificationConfigIndex : ConfigOperations {
*/
override suspend fun updateNotificationConfig(id: String, notificationConfigDoc: NotificationConfigDoc): Boolean {
createIndex()
val indexRequest = IndexRequest(INDEX_NAME)
val indexRequest = IndexRequest(INDEX_NAME).setRefreshPolicy(RefreshPolicy.IMMEDIATE)
.source(notificationConfigDoc.toXContent())
.create(false)
.id(id)
Expand Down
Copy link
Member

Choose a reason for hiding this comment

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

The Thread.sleep not only invoked in ChimeNotificationConfigCrudIT, I believe most integ tests about CRUD notification config having this proplem. Could you please find them and remove all these invocations?

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() {
""".trimIndent()
val configId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertNotNull(configId)
Thread.sleep(1000)

// Get chime notification config

Expand All @@ -52,7 +51,6 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() {
RestStatus.OK.status
)
verifySingleConfigEquals(configId, referenceObject, getConfigResponse)
Thread.sleep(100)

// Get all notification config

Expand All @@ -63,7 +61,6 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() {
RestStatus.OK.status
)
verifySingleConfigEquals(configId, referenceObject, getAllConfigResponse)
Thread.sleep(100)

// Updated notification config object
val updatedChime = Chime("https://updated.domain.com/updated_chime_url#0987654321")
Expand Down Expand Up @@ -94,7 +91,6 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() {
RestStatus.OK.status
)
Assert.assertEquals(configId, updateResponse.get("config_id").asString)
Thread.sleep(1000)

// Get updated chime notification config

Expand All @@ -105,12 +101,10 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() {
RestStatus.OK.status
)
verifySingleConfigEquals(configId, updatedObject, getUpdatedConfigResponse)
Thread.sleep(100)

// Delete chime notification config
val deleteResponse = deleteConfig(configId)
Assert.assertEquals("OK", deleteResponse.get("delete_response_list").asJsonObject.get(configId).asString)
Thread.sleep(1000)

// Get chime notification config after delete

Expand All @@ -120,7 +114,6 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() {
"",
RestStatus.NOT_FOUND.status
)
Thread.sleep(100)
}

fun `test BAD Request for multiple config data for Chime using REST Client`() {
Expand Down Expand Up @@ -180,7 +173,6 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() {
""".trimIndent()
val configId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertNotNull(configId)
Thread.sleep(1000)

// Update to slack notification config
val updateRequestJsonString = """
Expand Down Expand Up @@ -268,7 +260,6 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() {
""".trimIndent()
val configId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertNotNull(configId)
Thread.sleep(1000)

// update to new webhook URL
val updateRequestJsonString = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CreateNotificationConfigIT : PluginRestTestCase() {
""".trimIndent()
val configId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertNotNull(configId)
Thread.sleep(1000)


// Get Slack notification config

Expand Down Expand Up @@ -90,7 +90,7 @@ class CreateNotificationConfigIT : PluginRestTestCase() {
""".trimIndent()
val createdConfigId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertEquals(configId, createdConfigId)
Thread.sleep(1000)


// Get chime notification config

Expand Down Expand Up @@ -130,7 +130,7 @@ class CreateNotificationConfigIT : PluginRestTestCase() {
""".trimIndent()
val createdConfigId = createConfigWithRequestJsonString(createRequestJsonString)
Assert.assertEquals(configId, createdConfigId)
Thread.sleep(1000)


// Get Microsoft Teams notification config

Expand Down Expand Up @@ -174,7 +174,7 @@ class CreateNotificationConfigIT : PluginRestTestCase() {
)
val configId = createResponse.get("config_id").asString
Assert.assertNotNull(configId)
Thread.sleep(1000)


// Get webhook notification config

Expand All @@ -185,7 +185,7 @@ class CreateNotificationConfigIT : PluginRestTestCase() {
RestStatus.OK.status
)
verifySingleConfigEquals(configId, referenceObject, getConfigResponse)
Thread.sleep(100)


// Updated notification config object
val anotherWebhook = Webhook("https://another.domain.com/another_webhook_url#0987654321")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {

fun `test Delete single notification config`() {
val configId = createConfig()
Thread.sleep(1000)


// Get notification config by id
val getConfigResponse = executeRequest(
Expand All @@ -28,12 +28,12 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {
RestStatus.OK.status
)
verifySingleConfigIdEquals(configId, getConfigResponse)
Thread.sleep(100)


// Delete notification config
val deleteResponse = deleteConfig(configId)
Assert.assertEquals("OK", deleteResponse.get("delete_response_list").asJsonObject.get(configId).asString)
Thread.sleep(100)


// Get notification config after delete
executeRequest(
Expand All @@ -42,12 +42,12 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {
"",
RestStatus.NOT_FOUND.status
)
Thread.sleep(100)

}

fun `test Delete single absent notification config should fail`() {
val configId = createConfig()
Thread.sleep(1000)


// Get notification config by id
val getConfigResponse = executeRequest(
Expand All @@ -57,7 +57,7 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {
RestStatus.OK.status
)
verifySingleConfigIdEquals(configId, getConfigResponse)
Thread.sleep(100)


// Delete notification config
executeRequest(
Expand All @@ -70,7 +70,7 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {

fun `test Delete multiple notification config`() {
val configIds: Set<String> = (1..20).map { createConfig() }.toSet()
Thread.sleep(1000)


// Get all notification configs
val getAllConfigResponse = executeRequest(
Expand All @@ -80,15 +80,15 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {
RestStatus.OK.status
)
verifyMultiConfigIdEquals(configIds, getAllConfigResponse)
Thread.sleep(100)


// Delete notification config
val deleteResponse = deleteConfigs(configIds)
val deletedObject = deleteResponse.get("delete_response_list").asJsonObject
configIds.forEach {
Assert.assertEquals("OK", deletedObject.get(it).asString)
}
Thread.sleep(1000)


// Get notification configs after delete
val getAfterDelete = executeRequest(
Expand All @@ -98,12 +98,12 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {
RestStatus.OK.status
)
Assert.assertEquals(0, getAfterDelete.get("total_hits").asInt)
Thread.sleep(100)

}

fun `test Delete some items from multiple notification config with missing configs should fail`() {
val configIds: Set<String> = (1..19).map { createConfig() }.toSet()
Thread.sleep(1000)


// Get all notification configs
val getAllConfigResponse = executeRequest(
Expand All @@ -113,7 +113,7 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {
RestStatus.OK.status
)
verifyMultiConfigIdEquals(configIds, getAllConfigResponse)
Thread.sleep(100)


var index = 0
val partitions = configIds.partition { (index++) % 2 == 0 }
Expand All @@ -126,7 +126,7 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {
"",
RestStatus.NOT_FOUND.status
)
Thread.sleep(1000)


// Get notification configs after failed delete
val getAfterDelete = executeRequest(
Expand All @@ -136,12 +136,12 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {
RestStatus.OK.status
)
verifyMultiConfigIdEquals(configIds, getAfterDelete)
Thread.sleep(100)

}

fun `test Delete partial items from multiple notification config`() {
val configIds: Set<String> = (1..19).map { createConfig() }.toSet()
Thread.sleep(1000)


// Get all notification configs
val getAllConfigResponse = executeRequest(
Expand All @@ -151,7 +151,7 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {
RestStatus.OK.status
)
verifyMultiConfigIdEquals(configIds, getAllConfigResponse)
Thread.sleep(100)


var index = 0
val partitions = configIds.partition { (index++) % 2 == 0 }
Expand All @@ -164,7 +164,7 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {
deletedIds.forEach {
Assert.assertEquals("OK", deletedObject.get(it).asString)
}
Thread.sleep(1000)


// Get notification configs after delete
val getAfterDelete = executeRequest(
Expand All @@ -174,6 +174,6 @@ class DeleteNotificationConfigIT : PluginRestTestCase() {
RestStatus.OK.status
)
verifyMultiConfigIdEquals(remainingIds, getAfterDelete)
Thread.sleep(100)

}
}
Loading
Loading