1 00:00:00,960 --> 00:00:04,680 Our tests around the ticket update listener are looking pretty good but both the tests we have right 2 00:00:04,680 --> 00:00:09,350 now are really happy Pap tests there assume that everything is working as expected. 3 00:00:09,350 --> 00:00:14,490 I'd really like to add in at least one test to make sure that we can handle kind of bad scenarios as 4 00:00:14,490 --> 00:00:15,210 well. 5 00:00:15,210 --> 00:00:19,340 Let me show you a diagram and explain what I would like to test. 6 00:00:19,500 --> 00:00:20,270 Back to the side gram. 7 00:00:20,310 --> 00:00:21,960 We've looked at it many times. 8 00:00:21,960 --> 00:00:25,860 We're going to assume that inside of our orders database we've got a ticket with an idea Susie Q and 9 00:00:25,860 --> 00:00:32,230 A version of 1 Well then imagine that these two events right here get emitted and now maybe for whatever 10 00:00:32,230 --> 00:00:37,610 reason we accidentally process this second update event first. 11 00:00:37,840 --> 00:00:39,150 That is not what we would want. 12 00:00:39,160 --> 00:00:44,260 We would want to always process this event with the version to first but as we've seen it is entirely 13 00:00:44,260 --> 00:00:48,100 possible that we will accidentally process these things out of order. 14 00:00:48,690 --> 00:00:54,270 So in this scenario we've got a version of three on the incoming event but we still have only version 15 00:00:54,270 --> 00:00:59,670 1 inside of our database and so it's very clear that we are missing the event with version 2. 16 00:00:59,690 --> 00:01:04,500 So in this scenario we would want to either throw an error or at the very least make sure that we do 17 00:01:04,500 --> 00:01:06,900 not call the ACH function. 18 00:01:06,900 --> 00:01:10,980 Remember if we call the act function that means we are acknowledging the message and we are telling 19 00:01:10,980 --> 00:01:13,860 that string server that this event has been processed. 20 00:01:13,860 --> 00:01:18,030 If we just don't call the act function then that streaming server is going to try to emit this event 21 00:01:18,120 --> 00:01:18,480 again. 22 00:01:18,480 --> 00:01:23,520 Five seconds in the future and hopefully in that window we will have enough time to process the version 23 00:01:23,520 --> 00:01:26,070 to even that's it. 24 00:01:26,080 --> 00:01:27,310 That's all we're going to test. 25 00:01:27,310 --> 00:01:30,160 We're going to once again create an instance of our listener. 26 00:01:30,160 --> 00:01:34,960 We're going to create our data event and we're going to give it a version kind of far into the future 27 00:01:35,110 --> 00:01:39,620 and then just make sure that either we throw an error or at the very least that we do not call the ACH 28 00:01:39,760 --> 00:01:42,050 function. 29 00:01:42,100 --> 00:01:42,400 All right. 30 00:01:42,400 --> 00:01:50,100 So back inside my editor I'm gonna go down to the very bottom and I'll say it does not call EQ if the 31 00:01:50,160 --> 00:01:53,820 event is in the future. 32 00:01:53,820 --> 00:01:58,710 Or how about if the event has a future version. 33 00:01:58,710 --> 00:02:03,740 Or how about has a skipped version number or something like that. 34 00:02:03,750 --> 00:02:07,040 I'm sure you could think of a better description the one I've got good enough. 35 00:02:07,530 --> 00:02:14,660 I'll make sure I marked this function as a sink and inside of here we'll get message data listener. 36 00:02:14,670 --> 00:02:22,890 I don't think we need the ticket but let's get it anyways we might need it now we need to somehow make 37 00:02:22,890 --> 00:02:29,360 sure that our data object has a version that is far into the future so a future version we can do so 38 00:02:29,360 --> 00:02:34,010 very easily by just taking a look at the version property on there and sending it to some future version 39 00:02:34,010 --> 00:02:34,710 number. 40 00:02:35,110 --> 00:02:38,080 I'll just say data dot version equal to 10. 41 00:02:38,150 --> 00:02:42,560 That's definitely very far in the future and certainly there are some missing version events between 42 00:02:42,860 --> 00:02:48,580 the one that our ticket has or the current tickets version and this version of 10 right here. 43 00:02:48,630 --> 00:02:57,920 So now we will call our listener on message with that data object and message so when we run this now 44 00:02:58,220 --> 00:02:59,260 we should end up. 45 00:02:59,270 --> 00:03:02,310 If we go back over to the listener itself you're sick. 46 00:03:02,330 --> 00:03:07,120 Update listener when we run this query we should not be finding a ticket at all. 47 00:03:07,190 --> 00:03:12,990 We should enter this if statement and end up throwing in air and so we want to make sure that we somehow 48 00:03:13,020 --> 00:03:17,730 capture that air inside of our tests as we don't want to actually throw it inside the test itself. 49 00:03:17,760 --> 00:03:22,110 We need to capture that thing and then hopefully also write out some kind of expectation that says that 50 00:03:22,110 --> 00:03:27,260 the message not at function does not get called to do so. 51 00:03:27,260 --> 00:03:32,850 I'm going to wrap this thing with a try catch statement 52 00:03:35,910 --> 00:03:36,350 in this case. 53 00:03:36,360 --> 00:03:40,590 We're not really gonna do anything inside of the catch we're just using that catch to make sure that 54 00:03:40,590 --> 00:03:44,630 we do not throw an air out of this entire test which would automatically cause the entire thing to fail. 55 00:03:45,910 --> 00:03:50,530 Then right after the try catch statement we can put in an expectation we're going to expect message 56 00:03:50,530 --> 00:03:55,090 not ask not to have been called. 57 00:03:55,120 --> 00:03:55,970 That's our goal here. 58 00:03:55,990 --> 00:04:01,900 We want to make sure that we did not call that act function. 59 00:04:01,930 --> 00:04:08,770 Let's say this and see how we're doing back over at the terminal and it looks like our update listener 60 00:04:08,780 --> 00:04:10,840 tests are still passing as usual. 61 00:04:10,870 --> 00:04:12,300 Let's try to make this thing fail. 62 00:04:12,370 --> 00:04:15,100 Just make sure that the test is really working as expected. 63 00:04:15,770 --> 00:04:17,450 So how about in this scenario. 64 00:04:17,520 --> 00:04:20,180 Let's try changing about the data version right here. 65 00:04:20,520 --> 00:04:23,050 Let's just come at that out. 66 00:04:23,100 --> 00:04:28,630 So now we should have some accurate or correct version and we should be calling the ACT function. 67 00:04:28,800 --> 00:04:30,150 They'll say that pull it back over 68 00:04:33,590 --> 00:04:34,390 and there we go. 69 00:04:34,400 --> 00:04:40,670 So we got an error here because the act function was actually called well so oncoming that and I think 70 00:04:40,670 --> 00:04:43,300 we're good to go all right. 71 00:04:43,420 --> 00:04:47,410 So I think that's a good series of tests around our on message function. 72 00:04:47,440 --> 00:04:48,340 Let's take a pause right here. 73 00:04:48,370 --> 00:04:50,250 And as usual continue in just a moment.