Expected number of trials until success, with multiple variables per trial My software engineering team has a suite of tests we run on every checkin.  Some of these tests are flakey and fail some percentage of the time independently of the change we're making.  I want to quantify how much time this wastes for the devs.
Let $T_1, ..., T_n$ denote each test in the suite, and let $p_i$ denote the probability of success for the $i$'th test on a given run.  For each run of the suite, if  $T_i$ passes, that success is cached and the test will not be re-run. What is the expected number of suite runs until every test has passed?
 A: Let $X_i$ be the number of test suite runs until the test $T_i$ is succesfully finished. $X_i$ follows a negative binomial distribution with parameter $1-p_i$, i.e. $P(X_i = k) = (1-p_i)^{k-1} p_i$. This yields $P(X_i \le k) = p_i \sum \limits_{i=0}^{k-1}(1-p_i)^i = 1 - (1-p_i)^k$.
Now you are interested in the time until all tests were succesful, i.e. $N = \max(X_1, \ldots, X_n)$. To calculate this expectation, note that $P(N \le k) = P( X_i \le k \text{ for all } i) = \prod \limits_{i= 1}^n (1-(1-p_i)^k)$.
Finally, as $N$ is a discrete random variable the formula $E[N] = \sum \limits_{i=0}^n P(N > i) = \sum \limits_{i=0}^n 1-P(N \le i)$ holds.
It is probably not possible to give a closed expression of this term, but you can calculate approximations numerically.
A: It would be possible to do this calculation for specific cases using a Markov chain involving the $2^n$ joint states, but it is probably difficult to set out a simple general formula, particularly if the $p_i$ vary.   
For $n=1$ (geometric distribution), the answer is $\dfrac{1}{p_1}$  
For $n=2$, the answer is $\dfrac{{{p_1}^{2}}+p_1 p_2+{{p_2}^{2}}-{{p_1}^{2}} p_2-p_1 {{p_2}^{2}}}{p_1 p_2 \left( p_1+p_2-p_1 p_2\right) }$,  which reduces to the $\frac{1}{p_1}$ result when $p_2=1$, and to $\frac{3-2 p_1}{ p_1\left( 2-p_1\right) }$ when $p_2=p_1$
It just gets messier for larger $n$
