LinkTo projection seems to cause multiple dublicates of events

I have the following projection:

fromAll()
.when({
‘org.hltv.languageextension.ges.Event1’: function (s, e) {
linkTo(“Events-1”, e);
},
‘org.hltv.languageextension.ges.Event2’: function (s, e) {
linkTo(“Events-1”, e);
}
});

}


``

(I have two event types in their own stream, and now I link them to the stream 'Events-1')

When I run the following test:

@Test
public void weirdReplicatedEventsBug() throws InterruptedException {
List lotsOfEvent1s = lotsOfEvent1s(5);
List lotsOfEvent2s = lotsOfEvent2s(5);

repo.addAll("event-1", lotsOfEvent1s.stream());
repo.addAll("event-2", lotsOfEvent2s.stream());

Thread.sleep(1000);

assertEquals(lotsOfEvent1s.size(), repo.getAggregate("event-1").count());
assertEquals(lotsOfEvent2s.size(), repo.getAggregate("event-2").count());
assertEquals(lotsOfEvent1s.size() + lotsOfEvent2s.size(), repo.getAggregate("Events-1").count());

}


``

I create 5 of each events and put them into stream 'event-1' and 'event-2' respectively. I assert that there are 5 events in each stream.

But HORROR the last assertion fails with:

java.lang.AssertionError:

Expected :10

Actual   :860

``

(this is not a stable result. Actually sometimes the test passes :S )

The repository is a bit clunky so I created a  [repo gist](https://gist.github.com/mathiasbn/364c75257eef84f24ba4e2cbc1fada76).

I don't know if I supplied sufficient context (or too much...), but hope the mistake is mine and a simple fix.

What is actually in the stream event-1?

That was fast!
Well not sure what you mean. It’s 5 json events like:

0
event-1
org.hltv.languageextension.ges.Event1
2016-05-19 20:36:31
Data

{
  "data": "data1"
}

``

That looks correct no?

Oh maybe you mean ‘Events-1’ (sorry for the confusing naming).
Mostly (?) it’s empty in the web interface, but a few times it showed all the events, where it was events from the ‘event-1’ stream that was dublicated

Perhaps you can show us an example? (UI or atom feed would be best)

The issue is that when i query the linked-to stream (‘Events-1’), i get a huge amount of events (10 events added, 400+ returned)

Yes so I would like to see this stream and whats in it.

So while

http://localhost:56246/web/index.html#/streams/Events-1

``

is empty, the atom reply from

http://localhost:56246/streams/Events-1/0/forward/620
Accept:application/vnd.eventstore.atom+json

``

Gives

``

Oh. And I should say i’m using the in-memory version. Maybe thats the issue…
Thanks for helping out.

Nope. Not only in-memory. Just got it on our production ready test setup (way too many events, web client shows empty, and atom returns huge amount with lots of dublicates).

Nope. Not only in-memory. Just got it on our production ready test setup (way too many events, web client shows empty, and atom returns huge amount with lots of dublicates).

Do you have a reproduction?
If you don’t, but you have a db where you write a single event into a stream and duplicate linkTos occur? If so, can you share that DB with us and what events you are writing so that we can see what is happening here?