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

Re-set default index pattern in navigateToApp #8125

Merged
merged 9 commits into from
Aug 30, 2016
23 changes: 19 additions & 4 deletions test/support/page_objects/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ import {
import util from 'util';

import getUrl from '../../utils/get_url';

import {
config,
defaultTryTimeout,
defaultFindTimeout,
remote,
shieldPage
shieldPage,
esClient
} from '../index';

import {
Log,
Try,
Try
} from '../utils';

const mkdirpAsync = promisify(mkdirp);
Expand Down Expand Up @@ -83,8 +85,21 @@ export default class Common {
function navigateTo(url) {
return self.try(function () {
// since we're using hash URLs, always reload first to force re-render
self.debug('navigate to: ' + url);
return self.remote.get(url)
return esClient.getDefaultIndex()
.then(function (defaultIndex) {
if (appName === 'discover' || appName === 'visualize' || appName === 'dashboard') {
if (!defaultIndex) {
// https://github.com/elastic/kibana/issues/7496
// Even though most tests are using esClient to set the default index, sometimes Kibana clobbers
// that change. If we got here, fix it.
self.debug(' >>>>>>>> WARNING Navigating to [' + appName + '] with defaultIndex=' + defaultIndex);
self.debug(' >>>>>>>> Setting defaultIndex to "logstash-*""');
esClient.updateConfigDoc({'dateFormat:tz':'UTC', 'defaultIndex':'logstash-*'});
Copy link
Contributor

Choose a reason for hiding this comment

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

Does updateConfigDoc return a promise? If so, I think we should return that promise and then do the self.remote.get() call in a followup .then() block.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I think you're right about chaining the returned promise. I'll make that change.

}
}
self.debug('navigate to: ' + url);
return self.remote.get(url);
})
.then(function () {
return self.sleep(700);
})
Expand Down
29 changes: 28 additions & 1 deletion test/support/utils/es_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,39 @@ export default (function () {
);
} else {
configId = response.hits.hits[0]._id;
Log.debug('config._id =' + configId);
Log.debug('config._id = ' + configId);
return configId;
}
});
},

/*
** Gets defaultIndex from the config doc.
*/
getDefaultIndex: function () {
var defaultIndex;

return this.client.search({
index: '.kibana',
type: 'config'
})
.then(function (response) {
if (response.errors) {
throw new Error(
'get config failed\n' +
response.items
.map(i => i[Object.keys(i)[0]].error)
.filter(Boolean)
.map(err => ' ' + JSON.stringify(err))
.join('\n')
);
} else {
defaultIndex = response.hits.hits[0]._source.defaultIndex;
Log.debug('config.defaultIndex = ' + defaultIndex);
return defaultIndex;
}
});
},

/**
* Add fields to the config doc (like setting timezone and defaultIndex)
Expand Down