ActiveUsersMetricTests.mjs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { promisify } from 'node:util'
  2. import { expect } from 'chai'
  3. import Features from '../../../app/src/infrastructure/Features.mjs'
  4. import MetricsHelper from './helpers/metrics.mjs'
  5. import UserHelper from './helpers/User.mjs'
  6. const sleep = promisify(setTimeout)
  7. const User = UserHelper.promises
  8. const getMetric = MetricsHelper.promises.getMetric
  9. async function getActiveUsersMetric() {
  10. return getMetric(line => line.startsWith('num_active_users'))
  11. }
  12. describe('ActiveUsersMetricTests', function () {
  13. before(async function () {
  14. if (Features.hasFeature('saas')) {
  15. this.skip()
  16. }
  17. })
  18. it('updates "num_active_users" metric after a new user opens a project', async function () {
  19. expect(await getActiveUsersMetric()).to.equal(0)
  20. this.user = new User()
  21. await this.user.login()
  22. const projectId = await this.user.createProject('test project')
  23. await this.user.openProject(projectId)
  24. // settings.activeUserMetricInterval is configured to 100ms
  25. await sleep(110)
  26. expect(await getActiveUsersMetric()).to.equal(1)
  27. })
  28. })