Skip to content

Commit

Permalink
fix(#9166): backwards compatible couchdb views (#9171)
Browse files Browse the repository at this point in the history
Updates new couchdb view to be compatible with Couch 2
Adds test matrix for upgrade tests, to cover upgrades from latest release and from 4.2.4.

#9166
  • Loading branch information
dianabarsan committed Jun 17, 2024
1 parent 8432f5a commit 61a04a6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 16 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,17 @@ jobs:
upgrade:
needs: [publish]
name: Upgrade from latest release
name: Upgrade from ${{ matrix.version }}
runs-on: ubuntu-22.04
timeout-minutes: 60

if: ${{ github.event_name != 'pull_request' }}

strategy:
fail-fast: false
matrix:
version: [ '4.2.4', 'latest' ]

steps:
- name: Configure AWS credentials Public
if: ${{ env.INTERNAL_CONTRIBUTOR }}
Expand All @@ -423,6 +428,7 @@ jobs:
- name: Set ENV
run: |
echo "BUILDS_SERVER=$STAGING_SERVER" >> $GITHUB_ENV
echo "BASE_VERSION=${{ matrix.version }}" >> $GITHUB_ENV
- run: npm ci
- name: Create logs directory
run: mkdir tests/logs
Expand All @@ -432,7 +438,7 @@ jobs:
- name: Archive Results
uses: actions/upload-artifact@v4
with:
name: Upgrade
name: upgrade-${{ matrix.version }}
path: |
allure-results
allure-report
Expand Down
2 changes: 1 addition & 1 deletion ddocs/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"no-var": "off"
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 5
}
}
4 changes: 3 additions & 1 deletion ddocs/users-db/users/views/users_by_field/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ function(doc) {
}
if (doc.facility_id) {
var facilityIds = Array.isArray(doc.facility_id) ? doc.facility_id : [doc.facility_id];
facilityIds.forEach(facilityId => emit(['facility_id', facilityId]));
facilityIds.forEach(function(facilityId) {
emit(['facility_id', facilityId]);
});
}
}
7 changes: 5 additions & 2 deletions ddocs/users-meta-db/users-meta/views/device_by_user/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ function(doc) {
doc.metadata.month &&
doc.metadata.day
) {
const pad = number => number.toString().padStart(2, '0');
var pad = function (number) {
return number.toString().padStart(2, '0');
};

emit([doc.metadata.user, doc.metadata.deviceId], {
date: `${doc.metadata.year}-${pad(doc.metadata.month)}-${pad(doc.metadata.day)}`,
date: doc.metadata.year + '-' + pad(doc.metadata.month) + '-' + pad(doc.metadata.day),
id: doc._id,
device: {
userAgent: doc.device && doc.device.userAgent,
Expand Down
4 changes: 2 additions & 2 deletions ddocs/users-meta-db/users-meta/views/device_by_user/reduce.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function (keys, values) {
let latest = { date: '1970-01-01' };
values.forEach(function (value) {
var latest = { date: '1970-01-01' };
values.forEach(function(value) {
if (value.date > latest.date) {
latest = value;
}
Expand Down
20 changes: 17 additions & 3 deletions tests/e2e/upgrade/upgrade.wdio-spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const utils = require('@utils');

const { BRANCH, TAG } = process.env;
const { BRANCH, TAG, BASE_VERSION } = process.env;
const loginPage = require('@page-objects/default/login/login.wdio.page');
const upgradePage = require('@page-objects/upgrade/upgrade.wdio.page');
const commonPage = require('@page-objects/default/common/common.wdio.page');
Expand All @@ -11,6 +11,8 @@ const version = require('../../../scripts/build/versions');
const dataFactory = require('@factories/cht/generate');
const semver = require('semver');

const testFrontend = BASE_VERSION === 'latest';

const docs = dataFactory.createHierarchy({
name: 'offlineupgrade',
user: true,
Expand Down Expand Up @@ -52,8 +54,12 @@ describe('Performing an upgrade', () => {
await utils.saveDocs([...docs.places, ...docs.clinics, ...docs.persons, ...docs.reports]);
await utils.createUsers([docs.user]);

await loginPage.login(docs.user);
await commonPage.logout();
if (testFrontend) {
// a variety of selectors that we use in e2e tests to interact with webapp
// are not compatible with older versions of the app.
await loginPage.login(docs.user);
await commonPage.logout();
}

await loginPage.cookieLogin({
username: constants.USERNAME,
Expand All @@ -72,6 +78,10 @@ describe('Performing an upgrade', () => {
});

it('should have valid semver after installing', async () => {
if (!testFrontend) {
return;
}

const deployInfo = await utils.request({ path: '/api/deploy-info' });
expect(semver.valid(deployInfo.version)).to.be.ok;
});
Expand Down Expand Up @@ -117,6 +127,10 @@ describe('Performing an upgrade', () => {
state: 'finalized',
});

if (!testFrontend) {
return;
}

await adminPage.logout();
await loginPage.login(docs.user);
await commonPage.sync(true);
Expand Down
12 changes: 8 additions & 4 deletions tests/e2e/upgrade/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const rpn = require('request-promise-native');
const utils = require('@utils');
const wdioBaseConfig = require('../../wdio.conf');

const { MARKET_URL_READ, STAGING_SERVER, HAPROXY_PORT } = process.env;
const { MARKET_URL_READ, STAGING_SERVER, HAPROXY_PORT, BASE_VERSION } = process.env;
const CHT_COMPOSE_PROJECT_NAME = 'cht-upgrade';

const UPGRADE_SERVICE_DOCKER_COMPOSE_FOLDER = utils.makeTempDir('upgrade-service-');
Expand All @@ -28,7 +28,11 @@ const getUpgradeServiceDockerCompose = async () => {
await fs.promises.writeFile(UPGRADE_SERVICE_DC, contents);
};

const getLatestRelease = async () => {
const getRelease = async () => {
if (BASE_VERSION !== 'latest') {
return `medic:medic:${BASE_VERSION}`;
}

const url = `${MARKET_URL_READ}/${STAGING_SERVER}/_design/builds/_view/releases`;
const query = {
startKey: ['release', 'medic', 'medic', {}],
Expand All @@ -43,9 +47,9 @@ const getLatestRelease = async () => {
};

const getMainCHTDockerCompose = async () => {
const latestRelease = await getLatestRelease();
const release = await getRelease();
for (const composeFile of COMPOSE_FILES) {
const composeFileUrl = `${MARKET_URL_READ}/${STAGING_SERVER}/${latestRelease}/docker-compose/${composeFile}.yml`;
const composeFileUrl = `${MARKET_URL_READ}/${STAGING_SERVER}/${release}/docker-compose/${composeFile}.yml`;
const contents = await rpn.get(composeFileUrl);
const filePath = path.join(CHT_DOCKER_COMPOSE_FOLDER, `${composeFile}.yml`);
await fs.promises.writeFile(filePath, contents);
Expand Down

0 comments on commit 61a04a6

Please sign in to comment.