-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bae73f
commit 3909a53
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "srm-test" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
rand = "0.8.5" | ||
|
||
[dependencies.optimizely] | ||
path = "../../optimizely" | ||
features = ["online"] | ||
|
||
[dependencies.uuid] | ||
version = "1.3.0" | ||
features = ["v4", "fast-rng"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use optimizely::{decision::DecideOptions, Client}; | ||
use std::{collections::HashMap, error::Error, ops::AddAssign}; | ||
use uuid::Uuid; | ||
|
||
const FILE_PATH: &str = "../../datafiles/sandbox.json"; | ||
const FLAG_KEY: &str = "buy_button"; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
let client = Client::from_local_datafile(FILE_PATH)?.initialize(); | ||
|
||
// Do not send any decision events during SRM testing | ||
let decide_options = DecideOptions { | ||
disable_decision_event: true, | ||
..DecideOptions::default() | ||
}; | ||
|
||
// Create counter | ||
let mut counter: HashMap<String, usize> = HashMap::new(); | ||
|
||
// Run a two million times | ||
for _ in 0..2_000_000 { | ||
// Generate visitor ID using UUIDv4 | ||
let user_id = Uuid::new_v4().as_hyphenated().to_string(); | ||
|
||
// Get variation key | ||
let variation_key = client.create_user_context(&user_id) | ||
.decide_with_options(FLAG_KEY, &decide_options) | ||
.variation_key() | ||
.to_string(); | ||
|
||
// Count variation | ||
counter.entry(variation_key).or_insert(0).add_assign(1); | ||
} | ||
|
||
// Dump counter to stdout | ||
for (key, total) in counter { | ||
println!("Variation '{}' had {} visitors", key, total); | ||
} | ||
|
||
Ok(()) | ||
} |