resonate icon indicating copy to clipboard operation
resonate copied to clipboard

Add Announcements

Open dtornow opened this issue 3 months ago • 3 comments

Describe the problem you are facing

Resonate's Deterministic Simulation Testing cannot observe the Resonate Server beyond the request/response API. E.g. the Deterministic Simulation Testing cannot observe if notifications are actually sent.

Describe the solution you'd like

P-Lang style announcements & monitors. With announcements and monitors, DST will be able to verify that e.g. announcements are sent if a corresponding subscription exists.

Implementation Details

Step 1

Create a package announcements.

Step 2

Define an interface Announcement with a function

type Announcement interface {
    Announce(data map[string]string)
}

Step 3

Define two different implementations:

  • NopAnnouncement
  • DstAnnouncement

Step 4

Use a package-level private variable to hold a singleton instance. Instantiate the correct singleton instance based on config parameter on startup e.g.

package announcements

import "sync"

var (
    instance Announcement
    once     sync.Once
)

func Initialize(envType EnvironmentType) {
    once.Do(func() {
        switch envType {
        case Nop:
            instance = &NopAnnouncement{}
        case Dst:
            instance = &DstAnnouncement{}
        default:
            // Handle default case or throw an error
        }
    })
}

// Additional code to define EnvironmentType, NopAnnouncement, and DstAnnouncement follows...

Step 5

Implement the interface

  • Nop This will simply implement the Announce method without performing any operations.
  • Dst This will need to safely add the announcement data to an array for later verification. Ensure thread safety

dtornow avatar Apr 01 '24 02:04 dtornow