damccorm commented on a change in pull request #16980:
URL: https://github.com/apache/beam/pull/16980#discussion_r820782100



##########
File path: sdks/go/pkg/beam/core/runtime/exec/fn_test.go
##########
@@ -195,6 +196,50 @@ func TestInvoke(t *testing.T) {
        }
 }
 
+func TestRegisterCallback(t *testing.T) {
+       bf := bundleFinalizer{
+               callbacks:         []bundleFinalizationCallback{},
+               lastValidCallback: time.Now(),
+       }
+       testVar := 0
+       bf.RegisterCallback(500*time.Minute, func() error {
+               testVar += 5
+               return nil
+       })
+       bf.RegisterCallback(2*time.Minute, func() error {
+               testVar = 25
+               return nil
+       })
+       callbackErr := errors.New("Callback error")
+       bf.RegisterCallback(2*time.Minute, func() error {
+               return callbackErr
+       })
+
+       // We can't do exact equality since this relies on real time, we'll 
give it a broad range
+       if bf.lastValidCallback.Before(time.Now().Add(400*time.Minute)) || 
bf.lastValidCallback.After(time.Now().Add(600*time.Minute)) {
+               t.Errorf("RegisterCallback() lastValidCallback set to %v, want 
about 500 minutes", bf.lastValidCallback)
+       }
+       if got, want := len(bf.callbacks), 3; got != want {
+               t.Fatalf("RegisterCallback() called twice, got %v callbacks, 
want %v", got, want)
+       }
+
+       if err := bf.callbacks[0].callback(); err != nil {
+               t.Errorf("RegisterCallback() first callback returned error %v, 
want nil", err)
+       }
+       if got, want := testVar, 5; got != want {
+               t.Errorf("RegisterCallback() first callback set testvar to %v, 
want %v", got, want)
+       }
+       if err := bf.callbacks[1].callback(); err != nil {
+               t.Errorf("RegisterCallback() second callback returned error %v, 
want nil", err)
+       }
+       if got, want := testVar, 25; got != want {
+               t.Errorf("RegisterCallback() second callback set testvar to %v, 
want %v", got, want)
+       }
+       if err := bf.callbacks[2].callback(); err != callbackErr {
+               t.Errorf("RegisterCallback() second callback returned error %v, 
want %v", err, callbackErr)

Review comment:
       Yeah, I think adding it to the format string is cleaner - good call




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to