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

Tests: Ensure each test uses different watch ids #30331

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class SmokeTestWatcherWithSecurityIT extends ESRestTestCase {
private static final String TEST_ADMIN_USERNAME = "test_admin";
private static final String TEST_ADMIN_PASSWORD = "x-pack-test-password";

private String watchId = randomAlphaOfLength(20);
Copy link
Member

Choose a reason for hiding this comment

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

Should this be in a Before so it's unique per test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was under the impression, that it is unique per test with this.

public class MyTestCase extends ESTestCase {

    private String watchId = randomAlphaOfLength(20);

    public void testFoo() {
        logger.info("id {}", watchId);
    }

    public void testBar() {
        logger.info("id {}", watchId);
    }
}

results in

[2018-05-02T13:46:10,464][INFO ][o.e.t.MyTestCase         ] [testBar]: before test
[2018-05-02T13:46:10,960][INFO ][o.e.t.MyTestCase         ] id kXWMGSVERErlmIhKUbFd
[2018-05-02T13:46:11,182][INFO ][o.e.t.MyTestCase         ] [testBar]: after test
[2018-05-02T13:46:11,241][INFO ][o.e.t.MyTestCase         ] [testFoo]: before test
[2018-05-02T13:46:11,241][INFO ][o.e.t.MyTestCase         ] id WCGxKOTIEHxFSZIghhBy
[2018-05-02T13:46:11,242][INFO ][o.e.t.MyTestCase         ] [testFoo]: after test

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I am not sure why but my mind inserted a static into that field definition. That's clearly not there so of course what you have is fine.


@Before
public void startWatcher() throws Exception {
StringEntity entity = new StringEntity("{ \"value\" : \"15\" }", ContentType.APPLICATION_JSON);
Expand Down Expand Up @@ -87,7 +89,6 @@ public void startWatcher() throws Exception {

@After
public void stopWatcher() throws Exception {
adminClient().performRequest("DELETE", "_xpack/watcher/watch/my_watch");
assertOK(adminClient().performRequest("DELETE", "my_test_index"));

assertBusy(() -> {
Expand Down Expand Up @@ -147,14 +148,14 @@ public void testSearchInputHasPermissions() throws Exception {
builder.startObject("condition").startObject("compare").startObject("ctx.payload.hits.total").field("gte", 1)
.endObject().endObject().endObject();
builder.startObject("actions").startObject("logging").startObject("logging")
.field("text", "successfully ran my_watch to test for search inpput").endObject().endObject().endObject();
.field("text", "successfully ran " + watchId + "to test for search inpput").endObject().endObject().endObject();
builder.endObject();

indexWatch("my_watch", builder);
indexWatch(watchId, builder);
}

// check history, after watch has fired
ObjectPath objectPath = getWatchHistoryEntry("my_watch", "executed");
ObjectPath objectPath = getWatchHistoryEntry(watchId, "executed");
boolean conditionMet = objectPath.evaluate("hits.hits.0._source.result.condition.met");
assertThat(conditionMet, is(true));
}
Expand All @@ -174,11 +175,11 @@ public void testSearchInputWithInsufficientPrivileges() throws Exception {
.field("text", "this should never be logged").endObject().endObject().endObject();
builder.endObject();

indexWatch("my_watch", builder);
indexWatch(watchId, builder);
}

// check history, after watch has fired
ObjectPath objectPath = getWatchHistoryEntry("my_watch");
ObjectPath objectPath = getWatchHistoryEntry(watchId);
String state = objectPath.evaluate("hits.hits.0._source.state");
assertThat(state, is("execution_not_needed"));
boolean conditionMet = objectPath.evaluate("hits.hits.0._source.result.condition.met");
Expand All @@ -201,11 +202,11 @@ public void testSearchTransformHasPermissions() throws Exception {
.endObject().endObject().endObject();
builder.endObject();

indexWatch("my_watch", builder);
indexWatch(watchId, builder);
}

// check history, after watch has fired
ObjectPath objectPath = getWatchHistoryEntry("my_watch", "executed");
ObjectPath objectPath = getWatchHistoryEntry(watchId, "executed");
boolean conditionMet = objectPath.evaluate("hits.hits.0._source.result.condition.met");
assertThat(conditionMet, is(true));

Expand All @@ -232,10 +233,10 @@ public void testSearchTransformInsufficientPermissions() throws Exception {
.endObject().endObject().endObject();
builder.endObject();

indexWatch("my_watch", builder);
indexWatch(watchId, builder);
}

getWatchHistoryEntry("my_watch");
getWatchHistoryEntry(watchId);

Response response = adminClient().performRequest("GET", "my_test_index/doc/some-id",
Collections.singletonMap("ignore", "404"));
Expand All @@ -254,10 +255,10 @@ public void testIndexActionHasPermissions() throws Exception {
.endObject().endObject().endObject();
builder.endObject();

indexWatch("my_watch", builder);
indexWatch(watchId, builder);
}

ObjectPath objectPath = getWatchHistoryEntry("my_watch", "executed");
ObjectPath objectPath = getWatchHistoryEntry(watchId, "executed");
boolean conditionMet = objectPath.evaluate("hits.hits.0._source.result.condition.met");
assertThat(conditionMet, is(true));

Expand All @@ -278,10 +279,10 @@ public void testIndexActionInsufficientPrivileges() throws Exception {
.endObject().endObject().endObject();
builder.endObject();

indexWatch("my_watch", builder);
indexWatch(watchId, builder);
}

ObjectPath objectPath = getWatchHistoryEntry("my_watch", "executed");
ObjectPath objectPath = getWatchHistoryEntry(watchId, "executed");
boolean conditionMet = objectPath.evaluate("hits.hits.0._source.result.condition.met");
assertThat(conditionMet, is(true));

Expand All @@ -293,7 +294,7 @@ public void testIndexActionInsufficientPrivileges() throws Exception {
private void indexWatch(String watchId, XContentBuilder builder) throws Exception {
StringEntity entity = new StringEntity(Strings.toString(builder), ContentType.APPLICATION_JSON);

Response response = client().performRequest("PUT", "_xpack/watcher/watch/my_watch", Collections.emptyMap(), entity);
Response response = client().performRequest("PUT", "_xpack/watcher/watch/" + watchId, Collections.emptyMap(), entity);
assertOK(response);
Map<String, Object> responseMap = entityAsMap(response);
assertThat(responseMap, hasEntry("_id", watchId));
Expand Down