mediawiki-extensions-Popups/tests/node-qunit/getUserBucket.test.js
jdlrobson e4e9bb3bd6 Popups A/B test infrastructure
Introduce PopupsAnonsExperimentalGroupSize config variable. This defines
a population size who will be subject to experimentation. If the group
size is undefined or 0 (default) and PopupsBetaFeature is false
(default value) Popups will be enabled for everyone. If it is any other
value, half that group will see page previews.

Drop the config variable PopupsSchemaSamplingRate - we will now only
EventLog when an experiment is occuring. This means we can simplify the
MWEventLogger class as shouldLog will always be truthy. Given server
side eventlogging is only used for preference changes
traffic should be low and not need sampling.

Introduce getUserBucket which determines whether a user is in a bucket
on, off or control based on the value of
PopupsAnonsExperimentalGroupSize. Add tests showing how these
buckets are calculated.

Caution:
A kill switch wgPopupsEventLogging is provided for safety.
It defaults to false. Before merging, please check if any config changes
are necessary.

Bug: T171853
Change-Id: If2a0c5fceae78262c44cb522af38a925cc5919d3
2017-08-17 21:07:07 +00:00

36 lines
1.4 KiB
JavaScript

import * as stubs from './stubs';
import getUserBucket from '../../src/getUserBucket';
QUnit.module( 'ext.popups#getUserBucket' );
QUnit.test( 'If no users are subject to experiment everyone is bucketed as on', function ( assert ) {
assert.ok( getUserBucket( stubs.createStubExperiments( 'A' ), 0, 'a' ) === 'on' );
} );
QUnit.test( 'Define how experiment size impacts buckets', function ( assert ) {
var tests = [
[ 1, { off: 0, control: 0.5, on: 0.5 } ],
[ 0.9, { off: 0.1, control: 0.45, on: 0.45 } ],
[ 0.3, { off: 0.7, control: 0.15, on: 0.15 } ],
[ 0.5, { off: 0.5, control: 0.25, on: 0.25 } ],
[ 0.45, { off: 0.55, control: 0.225, on: 0.225 } ],
[ 0.006, { off: 0.994, control: 0.003, on: 0.003 } ]
];
tests.forEach( ( test ) => {
var actualBuckets,
experiments = stubs.createStubExperiments( 'A' ),
spy = this.sandbox.spy( experiments, 'getBucket' ),
expectedBuckets = test[ 1 ];
getUserBucket( experiments, test[ 0 ], 'a' );
actualBuckets = spy.getCall( 0 ).args[ 0 ].buckets;
// To avoid precision issues we'll need to test them all individually rather than check
// use calledWith. Otherwise we'll get some false positives.
assert.ok( actualBuckets.off.toFixed( 2 ) === expectedBuckets.off.toFixed( 2 ) );
assert.ok( actualBuckets.on.toFixed( 2 ) === expectedBuckets.on.toFixed( 2 ) );
assert.ok( actualBuckets.control.toFixed( 2 ) === expectedBuckets.control.toFixed( 2 ) );
} );
} );