Skip to content

Commit

Permalink
Merge branch 'slack-go:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq authored Sep 11, 2022
2 parents e70acbe + 6f5eda2 commit 0ebc113
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion files.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (api *Client) UploadFile(params FileUploadParameters) (file *File, err erro
func (api *Client) UploadFileContext(ctx context.Context, params FileUploadParameters) (file *File, err error) {
// Test if user token is valid. This helps because client.Do doesn't like this for some reason. XXX: More
// investigation needed, but for now this will do.
_, err = api.AuthTest()
_, err = api.AuthTestContext(ctx)
if err != nil {
return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions info.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,11 @@ func (t JSONTime) Time() time.Time {
func (t *JSONTime) UnmarshalJSON(buf []byte) error {
s := bytes.Trim(buf, `"`)

if bytes.EqualFold(s, []byte("null")) {
*t = JSONTime(0)
return nil
}

v, err := strconv.Atoi(string(s))
if err != nil {
return err
Expand Down
44 changes: 44 additions & 0 deletions info_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package slack

import (
"testing"
)

func TestJSONTime_UnmarshalJSON(t *testing.T) {
type args struct {
buf []byte
}
tests := []struct {
name string
args args
wantTr JSONTime
wantErr bool
}{
{
"acceptable int64 timestamp",
args{[]byte(`1643435556`)},
JSONTime(1643435556),
false,
},
{
"acceptable string timestamp",
args{[]byte(`"1643435556"`)},
JSONTime(1643435556),
false,
},
{
"null",
args{[]byte(`null`)},
JSONTime(0),
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var tr JSONTime
if err := tr.UnmarshalJSON(tt.args.buf); (err != nil) != tt.wantErr {
t.Errorf("JSONTime.UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
7 changes: 4 additions & 3 deletions socketmode/socket_mode_managed_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ func (smc *Client) run(ctx context.Context, connectionCount int) error {
}
}()

wg.Add(1)
// We don't wait on runMessageReceiver because it doesn't block on a select with the context,
// so we'd have to wait for the ReadJSON to time out, which can take a while.
go func() {
defer wg.Done()
defer cancel()

// The receiver reads WebSocket messages, and enqueues parsed Socket Mode requests to be handled by
Expand Down Expand Up @@ -162,7 +162,8 @@ func (smc *Client) run(ctx context.Context, connectionCount int) error {
return firstErr
}

// wg.Wait() finishes only after any of the above go routines finishes.
// wg.Wait() finishes only after any of the above go routines finishes and cancels the
// context, allowing the other threads to shut down gracefully.
// Also, we can expect firstErr to be not nil, as goroutines can finish only on error.
smc.Debugf("Reconnecting due to %v", firstErr)

Expand Down

0 comments on commit 0ebc113

Please sign in to comment.