You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43-12Lines changed: 43 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ Wrap a `use` block around the code's original behavior, and wrap `try` around th
24
24
25
25
* It decides whether or not to run the `try` block,
26
26
* Randomizes the order in which `use` and `try` blocks are run,
27
-
* Measures the durations of all behaviors,
27
+
* Measures the durations of all behaviors in seconds,
28
28
* Compares the result of `try` to the result of `use`,
29
29
* Swallow and record exceptions raised in the `try` block when overriding `raised`, and
30
30
* Publishes all this information.
@@ -62,7 +62,7 @@ class MyExperiment
62
62
63
63
attr_accessor:name
64
64
65
-
definitialize(name:)
65
+
definitialize(name)
66
66
@name= name
67
67
end
68
68
@@ -82,15 +82,10 @@ class MyExperiment
82
82
p result
83
83
end
84
84
end
85
-
86
-
# replace `Scientist::Default` as the default implementation
87
-
moduleScientist::Experiment
88
-
defself.new(name)
89
-
MyExperiment.new(name: name)
90
-
end
91
-
end
92
85
```
93
86
87
+
When `Scientist::Experiment` is included in a class, it automatically sets it as the default implementation via `Scientist::Experiment.set_default`. This `set_default` call is is skipped if you include `Scientist::Experiment` in a module.
88
+
94
89
Now calls to the `science` helper will load instances of `MyExperiment`.
95
90
96
91
### Controlling comparison
@@ -114,6 +109,38 @@ class MyWidget
114
109
end
115
110
```
116
111
112
+
If either the control block or candidate block raises an error, Scientist compares the two observations' classes and messages using `==`. To override this behavior, use `compare_error` to define how to compare observed errors instead:
Results aren't very useful without some way to identify them. Use the `context` method to add to or retrieve the context for an experiment:
@@ -233,7 +260,7 @@ def admin?(user)
233
260
end
234
261
```
235
262
236
-
The ignore blocks are only called if the *values* don't match. If one observation raises an exception and the other doesn't, it's always considered a mismatch. If both observations raise different exceptions, that is also considered a mismatch.
263
+
The ignore blocks are only called if the *values* don't match. Unless a `compare_error` comparator is defined, two cases are considered mismatches: a) one observation raising an exception and the other not, b) observations raising exceptions with different classes or messages.
237
264
238
265
### Enabling/disabling experiments
239
266
@@ -262,7 +289,7 @@ class MyExperiment
262
289
263
290
attr_accessor:name, :percent_enabled
264
291
265
-
definitialize(name:)
292
+
definitialize(name)
266
293
@name= name
267
294
@percent_enabled=100
268
295
end
@@ -400,6 +427,8 @@ Scientist rescues and tracks _all_ exceptions raised in a `try` or `use` block,
**Timeout ⏲️**: If you're introducing a candidate that could possibly timeout, use caution. ⚠️ While Scientist rescues all exceptions that occur in the candidate block, it *does not* protect you from timeouts, as doing so would be complicated. It would likely require running the candidate code in a background job and tracking the time of a request. We feel the cost of this complexity would outweigh the benefit, so make sure that your code doesn't cause timeouts. This risk can be reduced by running the experiment on a low percentage so that users can (most likely) bypass the experiment by refreshing the page if they hit a timeout. See [Ramping up experiments](#ramping-up-experiments) below for how details on how to set the percentage for your experiment.
431
+
403
432
#### In a Scientist callback
404
433
405
434
If an exception is raised within any of Scientist's internal helpers, like `publish`, `compare`, or `clean`, the `raised` method is called with the symbol name of the internal operation that failed and the exception that was raised. The default behavior of `Scientist::Default` is to simply re-raise the exception. Since this halts the experiment entirely, it's often a better idea to handle this error and continue so the experiment as a whole isn't canceled entirely:
@@ -544,6 +573,7 @@ Be on a Unixy box. Make sure a modern Bundler is available. `script/test` runs t
0 commit comments