Testing Mozilla Stumbler

Programming on Android is 97 kinds of awful.

The default choice is to use JUnit, which is mostly useless if you are using anything in the android.* namespace as a regular JVM will grind to a halt and die.

If you use robotium, you’re now involving at least an Android VM, or possibly running on real hardware – but the costs is that you will need to either spin up that VM or you need to have a device plugged in. Running tests involves loading code into your Android machine, starting up a full application and then instrumentation. This is slow and painful.

For Mozilla Stumbler, we made the choice to use robolectric[1] Robolectric fixes the “time to run tests” problem really well. Tests run in a regular JVM, they run reasonably quickly and you can get things running in a continuous integration platform without too much pain. We use it on Travis for the stumbler. Robolectric will play nice with JUnit4 so it’s not entirely jarring trying to wrap your head around it.

Your best bet here is to start reading some code to see what to do – a good place to start is the code that tests our software update in github.


@Config(emulateSdk = 18)
public class UpdaterTest {

    private Context ctx;
    private MainDrawerActivity activity;

    public void setUp() throws Exception {
        ctx = Robolectric.application;
        activity = Robolectric.newInstanceOf(MainDrawerActivity.class);
        Updater.sLastUpdateCheck = 0;

    public void testUpdater() {
        IHttpUtil mockHttp = new MockHttpUtil();

        Updater upd = new Updater();
        upd = spy(upd);

        // Setup mocks.
        // Replace the HTTP client and clock
        MockSystemClock clock = new MockSystemClock();
        long now = System.currentTimeMillis();
        ServiceLocator.getInstance().putService(IHttpUtil.class, mockHttp);
        ServiceLocator.getInstance().putService(ISystemClock.class, clock);

        // skip the exclusive wifi-only check

        assertFalse(upd.checkForUpdates(activity, ""));
        assertFalse(upd.checkForUpdates(activity, null));

        assertTrue(upd.checkForUpdates(activity, "anything_else"));
        assertEquals("1.3.0", upd.stripBuildHostName("1.3.0.Victors-MBPr"));
        assertEquals("1.3.0", upd.stripBuildHostName("1.3.0"));

Things to note:

You’re going to need the two annotations @Config and @RunWith on the test class to ensure that robolectric is enabled when your test is executed. If you forget these – you’re going to get bizarre errors when the regular JUnit4 tries to execute your testcases.

If you haven’t used JUnit in a long time, you’re also going to have to get used to the @Before and @Test annotations. Apparently things have changed in 10 years and methods named setUp or starting with test are no longer automatically picked up by JUnit.

There’s quite a bit happening in this little test. The Updater class is instantiated and we immediately wrap that with
a mockito spy. This lets us dynamically stub out behaviour – usually to no-op some function. In this case, we want to trick the Updater into thinking that a network is always available.

We also use a service locator pattern to dynamically inject dependencies into the stumbler. In this test, we inject
a fake system clock so that we can instrument time. The Updater class checks the system clock periodically – we want to
ensure that our test case runs the Updater with a known time.

The rest of the test case is the usual JUnit assertions.

If you run the tests from command line using : make test, you’ll get nice HTML output showing you your test results under the android/build/test-report/github/unittest/index.html path.

Library tests are also executed by make test and will show up under libraries/stumbler/build/test-report/debug/index.html

Those are the basics – robolectric lets you instrument android UI bits as well which I’ll cover in the next post.


Sex work, C-36 and what people ought to do

tl;dr –

Bill C-36 is terrible and will probably get people killed.  At best, it’s probably unconstitutional. At worst, it’s going to get people killed.  Go ask Premier Wynne to refer bill C-36 to the Court of Appeal to verify that it is indeed constitutional and doesn’t infringe on sex worker’s charter rights.

Stop complaining about shitty government and shitty laws.  Do something.

Fill in this webform or email her directly.  Put your real name and real mailing address and make this count.  If you’re looking for a template, you can use this.

The backstory

Bill C-36 was given royal assent last week – coincidentally, on my birthday.  Shitty birthday present Peter MacKay.  Shitty birthday present.

For those that follow me on Twitter, it’s no secret that I think the bill is terrible.

So some background for those that aren’t policy wonks.

In December 2013, sex workers won a charter of rights challenge against the federal government of Canada. Three provisions were struck down that were shown to cause harm to sex workers:

  • s. 210 (keeping or being found in a bawdy house),
  • s. 212(1)(j) (living on the avails of prostitution), and
  • s. 213(1)(c) (communicating in public for the purpose of prostitution)

those parts of the criminal code were found to violate section 7 of the Charter of Rights. That’s this bit for those whose memory of high school political science is fuzzy:

Everyone has the right to life, liberty and security of the person and the
right not to be deprived thereof except in accordance with the principles of
fundamental justice.

So let’s first be totally clear, when people say that the old laws caused harm – it means the old laws helped to get people assaulted, raped or worse – killed.

In it’s judgement, the court was extremely clear:

The impugned laws negatively impact security of the person rights of prostitutes and thus engage s. 7 The proper standard of causation is a flexible “sufficient causal connection” standard, as correctly adopted by the application judge.  The prohibitions all heighten the risks the applicants face in prostitution — itself a legal activity.  They do not merely impose conditions on how prostitutes operate.  They go a critical step further, by imposing dangerous conditions on prostitution; they prevent people engaged in a risky — but legal — activity from taking steps to protect themselves from the risks.  That causal connection is not negated by the actions of third‑party johns and pimps, or prostitutes’ so‑called choice to engage in prostitution.  While some prostitutes may fit the description of persons who freely choose (or at one time chose) to engage in the risky economic activity of prostitution, many prostitutes have no meaningful choice but to do so.  Moreover, it makes no difference that the conduct of pimps and johns is the immediate source of the harms suffered by prostitutes.  The violence of a john does not diminish the role of the state in making a prostitute more vulnerable to that violence.

The Supreme Court of Canada gave parliament 12 months to enact new laws, or else sex work would become fully decriminalized.  That is to say – sex work would be treated like any other job.

Bill C-36 is the “Protection of Communities and Exploited Persons Act”. It’s the new law passed by the federal government.  This bill manages to take all the harms of the old laws, and make things dramatically worse.

Before I go on anymore, it’s time for a break.  This is how I hope you are responding to “worse laws than the ones that got people killed” :

So what do we know about sex work?  Quite a lot actually.

We know that sex workers aren’t the stereotype of a diseased person carrying HIV/AIDS.  That trope has been widely debunked with real research.

We know that from a health policy perspective, decriminalization leads to better health outcomes.  That’s UNAIDS.  The Lancet just this year published a massive body of research that supports decriminalization – purely on the health impact.  The BMJ published research this year that indicates that criminalization of clients negatively impacts the safety and health of sexworkers.

That’s the health policy side of this.

What do we know about trafficking?  Well – to the best of my knowledge, I’d say most data that shows there’s a wide spread sex trafficking problem is either intentionally misleading, or done by some of the worst researchers I’ve ever had to read.

If you’re to believe the numbers from the anti-trafficking groups and law enforcement, you’d have to believe that roughly 25-40% of all men in Ottawa between the ages of 18-60 see one drug addled sex trafficked woman every year.  That’s a pretty sad view of humanity.

It’s also pretty ridiculous.

You can go through the numbers yourself, but a sex worker has done the work for you – and compiled all the data over here.  Warning – it’s an escort site. I guess that means it’s NSFW depending on where you work.

Sometimes, the timing of things is just a little too suspicious.  Just as bill C-36 went to the Justice Committee this past summer, the obviously inflated numbers published by the CSEC which were normally found here disappeared.  That happened literally the day before the committees started.

What do legal bodies think?  The Canadian Bar Association :

“We believe the Bill potentially imperils prostitutes going forward by restricting their ability to protect themselves in their inherently risky, but legal activities,”

The most important voices of all – the ones that have the most skin in the game – sex workers themselves and sex work support organizations have been very clear, C-36 will kill people.

There’s more, but I think my point is pretty clear.

Ok, fine.  So now what?

I worry that our government shows an alarming level of contempt for people.  You can see it in bill C-2 which will make safe injection difficult to access.  You can see it in bill C-13 and privacy regulations.  You can see it in C-32, the Victim’s Bill of Rights.

So what now?

There’s been a call to get the Premier of Ontario to refer the bill to the Ontario Court of Appeals.

How this works – while parliament can pass bills, it’s up to the provinces to administer the law. The Courts of Justice act allows the Attorney General to refer questions to the Court of Appeal.  That court can render an opinion on the constitutionality of a law and that opinion is legally binding.
So here’s what you’re going to do Internet.  If you live in Ontario, you’re going to email the premier and ask for something small.  You’re going to ask her to refer bill C-36 to the Court of Appeal to check that it is constitutional and doesn’t infringe on charter rights.

You get the shitty government you deserve.  So demand a better one by demanding better laws.

Fill in this webform or email her directly.  Put your real name and real mailing address and make this count.

Upgrading the Open Access Button

The Open Access Button is getting an upgrade.

Back in January, I talked about extending the Open Access Button to capture links to open access journal papers.

That patch is going to go live real soon now.  There’s some minor tests I need to close off prior to launch but we’re closing in on that.  You can see the on the OAButton github repository.

Once this patch is live, we’re going to start collecting links for Open Access versions of publications and start sharing those with people.

This works pretty simply – the first time a pay wall is hit for a paper, we will now try to determine the author email address and then notify the author that the research is unavailable to the public.

We provide a link that the author can click on to submit an open version of their paper.

Every time someone hits the pay wall after that, the user will be notified where to find the open version of their paper.

We still need your help on this.

There are still some rough edges here.  Right now, I only allow the author to submit the link.  That means we have no way for the general public to participate in supplying links to open versions of papers.  I’m doing this because I don’t know of a good way to prevent abuse where invalid links are submitted.

If we can solve that problem – we can provide a public API where individuals can start contributing links to open access papers.  Cracking this nut would be a huge win.  If we could provide a public API – we can build more tools to integrate to the OAButton and we could dramatically increase the number of people contributing links to papers.

We could also use some love to restyle some of the HTML emails and some of the webpages.  If you have design skills – we need you too. 🙂

This stuff is important.   Let’s fix this.

A note about self deposit repositories:

I didn’t re-use any of the self-deposit systems that individuals and libraries have setup for themselves.  Unfortunately – there’s no rational way of integrating any of these things.   While authors may have deposited a copy of a  pre-print of final draft somewhere, I have no way of determining where that is.  Even if I did, I have no way of querying that system.  I have no way of resolving if the document I find in the system is the same as the document that has been blocked.

If you run one of these systems – we want to work with you.  We just don’t have a way to do that yet.  Let’s figure this out.

Campbell Walsh Urology 11th Edition will revise PVPS risks to 1-2% of patients

I win at the internet.  Sort’ve.

Post-vasectomy pain syndrome has had this “1 in 1000” patient number floating around for a while, and I’ve never been able to track down where it came from until the last couple of months.   Turns out – that numbers is bunk.

After a series of 35 emails back and forth with Elsevier, the publisher of Campbell Walsh Urology – I can confirm now that the 11th edition will include dramatically higher risks for incurring post-vasectomy pain syndrome.

The 10th edition has this to say on the topic:

Up to 30% of men have short-term scrotal pain lasting a few weeks. However, postvasectomy pain syndrome, or long- term scrotal pain after vasectomy, occurs in approximately one in 1000 vasectomies, although some report the incidence to be as high as 15% (McConaghy et al, 1996; Awsare et al, 2005; Tandon and Sabanegh, 2008).

If you take the time to go through those citations, no such claim is actually made.

McConaghy 1996:

Following a study by McMahon et al. which found that 33% of patients were troubled with chronic testicular discomfort following vasectomy [1], a study was undertaken at our hospital to examine ways of reducing the incidence of this problem. This work has been published recently [2] and we would like to draw your readers’ attention to the relevant findings.

This may result from congestive epididymitis or the development of sperm granuloma. The incidence of chronic orchalgia is quite high (12–52%). [5] The proportion of patients, however, whose quality of life was affected, or those who sought treatment was much lower (2.2–15%)

Tandon 2008 is more complex.  It has this to say:
PVPS is disappointingly common and difficult to treat. Although early pain lasting for a few weeks is fairly common after vasectomy (present in up to 30% of men), longterm pain requiring some kind of intervention or surgical therapy occurs in up to one in 1000 vasectomized men [4].
Tracking down the claim for one in 1000 vasectomized men in citation 4 gives us :
Sandlow JI, Winfield HN, Goldstein M. Surgery of the scrotum and seminal vesicles. In Wein AJ, Kavoussi LR, Novick AC, Partin AW eds, Campbell-Walsh Urology, 9th edn. Philadelphia: WB Saunders, 2006: 1103–9

So what we have is Campbell Walsh citing a paper which cites Campbell Walsh.

There’s never been any evidence that supported the claim of 1 in 1000 number.

So that’s the good news.  That number is going away.

I’m told by the reviewers in Elsevier that they will be using Leslie 2007 for most of their new data and they will also be using the AUA guidelines.

Unfortunately, you won’t be able to verify this until 2016 because Elsevier can’t seem to figure out how to use the internet to publish errata.

Yes – you will need to wait for the dead tree version of the book to come out.

The irony here is a bit thick even for me.

BJU offers open access to Leslie 2007.  After I compiled the trail of papers that made this error possible – I asked to review the draft of the new chapter on vasectomy.  That was October 1.

Here’s the response:  “..it would be highly inappropriate to provide a draft chapter prior to the text being published.

Screw you Elsevier.

You can call me The Doctor

tl;dr – I’ve killed the 0.1-0.25% occurrence rate line in UpToDate. Your doctor can verify the change in the section “Vasectomy and other vasal occlusion techniques for male contraception”. The newly revised number is simply : 2% for severe life quality affecting pain. Your doctor may not be aware of this as the change is not listed yet in the changelog that UpToDate provides users.

Edit: UpToDate has no intention of making this more visible.

No, it is not an oversight that the change is not in What’s new. Only selected topic updates will appear there, and generally those that represent significant alterations in treatment-related decisions.

So I had my surgery on of all day’s – Valentine’s day.

As they wheeled me into the operating room, I told one of the nurses that I was hoping an entirely different kind of valentine’s day. In a southern drawl, she said:

You just tell the boys back home that you were naked with three cute brunettes.

So, it’s been 3 weeks post-op and I’m happy to say that it looks like surgery was successful.   There’s still another 3 or 4 more months to go to be completely sure, but right now – things look really really awesome.

That would be enough for me to do the happy dance, but the thing that’s had me grinning from ear to ear since Friday?

I got my edit to UpToDate accepted.  It’s a small tiny edit, but it’s one that fixes an error that’s been perpetuated for about 30 years near as I can tell.

For those that are unaware, UpToDate is a massively deployed clinician’s database used by doctors around the world as a decision support resource. It’s used by 700,000 doctors globally. That’s a lot.  When I first started posting up on Reddit a couple months back, a redditor pointed me at the numbers in UpToDate as a reference that all doctors are going to use as a point of reference.

Before March 1, 2013, you would have found this in UpToDate:

The post-vasectomy pain syndrome is distinct from post-procedure pain, however, there is some controversy regarding its definition, and therefore prevalence. Rates for the post-vasectomy pain syndrome have been reported as 0.1 to 0.25 percent [41,42]. However, surveys have found that “troublesome” post-vasectomy pain is reported by as many as 15 percent of men, with pain severe enough to impact quality of life in 2 percent; survey respondents, however, may not have been representative of all post-vasectomy men [43,44].

That bold section is gone now.  Without it, it reads quite differently.  It looks like this now:

Historically, rates for the post-vasectomy pain syndrome have been reported as very low (<1 percent). However, surveys have found that the incidence of “troublesome” post-vasectomy pain is reported by about 15 percent of men, with pain severe enough to impact quality of life in 2 percent; survey respondents, however, may not have been representative of all post-vasectomy men [40,41].

I’m annoyed still that the <1% number shows up at all.  The two works cited by UpToDate in the newly revised text only show data that support the 15% occurrence rate.  You can read it yourself in Manikandan 2004 and McMahon 1992.

UpToDate has this to say on the matter:

Incidence reporting in the literature varies widely, The lower incidence figures reflect older literature, with the more contemporary data suggesting that the incidence of this problem is probably higher.

(emphasis is mine)

This weirdly reminds me of watching traders dissect the wording of the Fed every time a rate announcement is made in an attempt to find the ‘true’ meaning of the wording. I think my chinese ancestors called this “reading tea leaves”.  But I digress.

The snarky part of me wishes they’d reword the first sentence to “Historically – we couldn’t bother to do division properly, or read anything.”.  Just before I left for Winter Haven, I ended up pulling the articles cited in UpToDate.  What I found was pretty bad. You can see the full details here.

It turns out – the M in MD is not for math.  Of the two citations, one was a completely different topic, and the JAMA study from 1984 never made any claim that supported the 0.1 to 0.25% occurrence rate.  In fact, the study in 1984 explicitly shows 187 patients out of 10,590 had chronic pain.

I guess calculating 187/10,590 is a really hard thing to do.

The literature does vary widely, but as far as I can tell – there’s still no evidence to support the historical figures.   We can argue about the strength and validity of particular studies, but you don’t get to argue about numbers that just aren’t there.

As they say:  Every man is entitled to his own opinion, but not his own facts.

This kind of mistake happens all the time.  If you haven’t been following the mess going on in cancer research or the debacle that’s going on in academia with respect to peer review – it’s a disaster.   Statistical errors happen all the time now – it’s estimated that it’s happening ~15% of the time.

That though is a rant for another day.  Today – I’m celebrating my small victory.

On a side note – every email I ever got from UpToDate was addressed to “Dr. Ng”.  If anyone else wants to call me “The Doctor” – I’m totally cool with that.

Next post – something entirely nerdy.

Cutting and pasting from German is hard

Sometimes people mess up translations.

Maybe it’s the gutteral sounds of German.

Medline incorrectly got the lower bound of chronic pain post vasectomy as 0.5% when it should be 3%.  Here’s the correction I’ve filed with Pubmed and the original full text (in German).

PubMed link: http://www.ncbi.nlm.nih.gov/pubmed/21845426

You can find the data in Table 2.

PMID:  21845426
TITLE: Ischemic testicular necrosis following vasectomy: rare and typical complications of an outpatient procedure
TEXT: Late complications are chronic pain (0.5-18%), pain during sex (2.9%), hydrocele (0-4%) as well as spermatocele (1.6%)
CORRECTION: Late complications are chronic pain (3-18%), pain during sex (2.9-5%), hydrocele (0-4%) as well as spermatocele (1.6%)
NOTE:  The data in question is in Table 2 on the fourth page. I’ve attached the article for your reference.

Original journal article:  Ischemic testicular necrosis following vasectomy: rare and typical complications of an outpatient procedure