<commit_before>'use strict';

// Simulate a service provider submitting usage for a service, check the
// usage report for those submissions and measure the performance.

// TODO Use Hystrix metrics for internal performance measurements

// Scenarios:
// - Concurrently submit a usage doc for a service instance
// - Concurrently submit a usage doc for multiple service instances
// - Concurrently submit a usage doc for multiple organizations
// - TODO add service and space variations
// - TODO submit batch of usage docs in each submission

const _ = require('underscore');

const commander = require('commander');

const request = require('abacus-request');
const throttle = require('abacus-throttle');
const util = require('util');

const map = _.map;
const range = _.range;
const omit = _.omit;

// Setup the debug log
const debug = require('abacus-debug')('abacus-test-perf');

commander.option(
  '-o, --orgs <n>', 'Number of organizations', parseInt);
commander.option(
  '-i, --instances <n>', 'Number of service instances', parseInt);
commander.option(
  '-u, --usagedocs <n>', 'Number of usage docs', parseInt);
commander.option(
  '-d, --delta <d>', 'Usage time window shift in milli-seconds', parseInt);

commander.parse(process.argv);

// Number of organizations
const orgs = commander.orgs || 1;

// Number of service instances
const serviceInstances = commander.instances || 1;

// Number of usage docs
const usage = commander.usagedocs || 1;

// Usage time window shift in milli-seconds
const delta = commander.delta || 0;

describe('abacus-test-perf', () => {
  it('measures the performance of concurrent usage submissions', (done) => {
    // Configure the test timeout based on the number of usage docs, with
    // a minimum of 20 secs
    const timeout = Math.max(20000,
      100 * orgs * serviceInstances * usage);
    this.timeout(timeout + 2000);

    // Return a usage with unique start and end time based on a number
    const start = 1435629365220 + delta;
    const end = 1435629465220 + delta;
    const siid = (o, si) => ['0b39fa70-a65f-4183-bae8-385633ca5c87',
      o + 1, si + 1].join('-');
    const orgid = (o) => ['a3d7fe4d-3cb1-4cc3-a831-ffe98e20cf27',
      o + 1].join('-');

    const usageTemplate = (o, si, i) => ({
        service_instances: [{
          service_instance_id: siid(o, si),
          usage: [{
            start: start + i,<commit_msg>Fix Babel transpiler issue with performance test code<commit_after>'use strict';

// Simulate a service provider submitting usage for a service, check the
// usage report for those submissions and measure the performance.

// TODO Use Hystrix metrics for internal performance measurements

// Scenarios:
// - Concurrently submit a usage doc for a service instance
// - Concurrently submit a usage doc for multiple service instances
// - Concurrently submit a usage doc for multiple organizations
// - TODO add service and space variations
// - TODO submit batch of usage docs in each submission

const _ = require('underscore');

const commander = require('commander');

const request = require('abacus-request');
const throttle = require('abacus-throttle');
const util = require('util');

const map = _.map;
const range = _.range;
const omit = _.omit;

// Setup the debug log
const debug = require('abacus-debug')('abacus-test-perf');

commander.option(
  '-o, --orgs <n>', 'Number of organizations', parseInt);
commander.option(
  '-i, --instances <n>', 'Number of service instances', parseInt);
commander.option(
  '-u, --usagedocs <n>', 'Number of usage docs', parseInt);
commander.option(
  '-d, --delta <d>', 'Usage time window shift in milli-seconds', parseInt);

commander.parse(process.argv);

// Number of organizations
const orgs = commander.orgs || 1;

// Number of service instances
const serviceInstances = commander.instances || 1;

// Number of usage docs
const usage = commander.usagedocs || 1;

// Usage time window shift in milli-seconds
const delta = commander.delta || 0;

describe('abacus-test-perf', () => {
  it('measures performance of concurrent usage submissions', function(done) {
    // Configure the test timeout based on the number of usage docs, with
    // a minimum of 20 secs
    const timeout = Math.max(20000,
      100 * orgs * serviceInstances * usage);
    this.timeout(timeout + 2000);

    // Return a usage with unique start and end time based on a number
    const start = 1435629365220 + delta;
    const end = 1435629465220 + delta;
    const siid = (o, si) => ['0b39fa70-a65f-4183-bae8-385633ca5c87',
      o + 1, si + 1].join('-');
    const orgid = (o) => ['a3d7fe4d-3cb1-4cc3-a831-ffe98e20cf27',
      o + 1].join('-');

    const usageTemplate = (o, si, i) => ({
        service_instances: [{
          service_instance_id: siid(o, si),
          usage: [{
            start: start + i,
{'fraction_non_alphanumeric': 0.12538795779019243, 'fraction_numerical': 0.03476101800124146, 'mean_word_length': 3.484230055658627, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2730950', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1435, 'n_words': 519}