Bug fix: generateViewEvent() requires Solr to commit stats immediately.

This commit is contained in:
Tim Donohue
2023-03-07 15:02:31 -06:00
parent 371bd072b3
commit 61ace6f831
2 changed files with 13 additions and 2 deletions

View File

@@ -133,6 +133,10 @@ Cypress.Commands.add('loginViaForm', loginViaForm);
* Generate statistic view event for given object. Useful for testing statistics pages with * Generate statistic view event for given object. Useful for testing statistics pages with
* pre-generated statistics. This just generates a single "hit", but can be called multiple times to * pre-generated statistics. This just generates a single "hit", but can be called multiple times to
* generate multiple hits. * generate multiple hits.
*
* NOTE: This requires that "solr-statistics.autoCommit=false" be set on the DSpace backend
* (as it is in our docker-compose-ci.yml used in CI).
* Otherwise, by default, new statistical events won't be saved until Solr's autocommit next triggers.
* @param uuid UUID of object * @param uuid UUID of object
* @param dsoType type of DSpace Object (e.g. "item", "collection", "community") * @param dsoType type of DSpace Object (e.g. "item", "collection", "community")
*/ */
@@ -169,9 +173,13 @@ function generateViewEvent(uuid: string, dsoType: string): void {
cy.request({ cy.request({
method: 'POST', method: 'POST',
url: baseRestUrl + '/api/statistics/viewevents', url: baseRestUrl + '/api/statistics/viewevents',
headers: { [XSRF_REQUEST_HEADER] : csrfToken}, headers: {
[XSRF_REQUEST_HEADER] : csrfToken,
// use a known public IP address to avoid being seen as a "bot"
'X-Forwarded-For': '1.1.1.1',
},
//form: true, // indicates the body should be form urlencoded //form: true, // indicates the body should be form urlencoded
body: { targetId: uuid, targetType: dsoType } body: { targetId: uuid, targetType: dsoType },
}).then((resp) => { }).then((resp) => {
// We expect a 201 (which means statistics event was created) // We expect a 201 (which means statistics event was created)
expect(resp.status).to.eq(201); expect(resp.status).to.eq(201);

View File

@@ -30,6 +30,9 @@ services:
db__P__url: 'jdbc:postgresql://dspacedb:5432/dspace' db__P__url: 'jdbc:postgresql://dspacedb:5432/dspace'
# solr.server: Ensure we are using the 'dspacesolr' image for Solr # solr.server: Ensure we are using the 'dspacesolr' image for Solr
solr__P__server: http://dspacesolr:8983/solr solr__P__server: http://dspacesolr:8983/solr
# Tell Statistics to commit all views immediately instead of waiting on Solr's autocommit.
# This allows us to generate statistics in e2e tests so that statistics pages can be tested thoroughly.
solr__D__statistics__P__autoCommit: 'false'
depends_on: depends_on:
- dspacedb - dspacedb
image: dspace/dspace:dspace-7_x-test image: dspace/dspace:dspace-7_x-test